aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Run time error...tricky one.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Run time error...tricky one.." Watch "Run time error...tricky one.." New topic
Author

Run time error...tricky one..

Vipul Tangri
Greenhorn

Joined: Nov 09, 2000
Posts: 11
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);
}
}
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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

Joined: Nov 09, 2000
Posts: 11
Thx Stevens.....
vipul
 
Don't get me started about those stupid light bulbs.
 
subject: Run time error...tricky one..
 
Similar Threads
help on reading textfield on 1 class from another class and using it to create a file
mnemonics are not getting focus for the menubar
toolbar in internalframe
Scrolling JMenu
Why menu doesn't display