• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Run time error...tricky one..

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have a problem...
i have two source files by the name of MenuFrame which is used to make Menu and another to make frame..
Both files get compiled without error but on run time doesnot show menu..
why?
i am producing the source code for the both files
thx.
vipul

// MenuFrame.java to create menus
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class MenuFrame extends JMenuBar
{
public JMenu menu;
public JMenuItem menu1, menu2,menu3,menu4;
public JMenuBar menuBar;
public MenuFrame()
{
menuBar = new JMenuBar();
menu=new JMenu ("All Frames");
menu.setMnemonic(KeyEvent.VK_T);
menuBar.add(menu);
menu1= new JMenuItem("CD Frame");
menu2=new JMenuItem("Customer Frame");
menu3= new JMenuItem("Transaction Frame");
menu4=new JMenuItem("Exit");

menu.add(menu1);
menu.addSeparator();
menu.add(menu2);
menu.addSeparator();
menu.add(menu3);
menu.addSeparator();
menu.add(menu4);
}
}
//VcFrame.java to create frame which contains menu and just one button

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class VcFrame extends JFrame implements ActionListener
{
protected JButton button;
public VcFrame()
{
button=new JButton("Hello World");
Container contentPane=getContentPane();
contentPane.add(button);
setJMenuBar(new MenuFrame());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
}
public static void main(String[] args)
{
JFrame f= new VcFrame();
f.setSize(200,200);
f.setLocation(200,200);
f.setVisible(true);
}
}
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In MenuFrame
change:
menuBar.add(menu);

to:
add(menu);
Remove the menuBar variable totally. The class is a JMenuBar so you don't need that variable.
 
Vipul Tangri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx Stevens.....
vipul
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic