Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run time error...tricky one..

 
Vipul Tangri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • 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);
}
}
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thx Stevens.....
vipul
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic