Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kevin Jenkins   on Aug 26 In Java Category.

  
Question Answered By: Brian Ross   on Aug 26

After rearranging and slight modification of your code, here now
is your runnable code  

import javax.swing.*;import java.awt.*;import java.awt.event.*;
public class  FinalMenu extends JFrame
public  FinalMenu()
{ Container contentPane = getContentPane();
JMenuBar mb = new JMenuBar();
JMenu master  = new JMenu("Master");
JMenuItem exitItem = new JMenuItem("Exit");
JMenuItem general,employee,item,model;
master.add(general = new JMenuItem("General"));
master.add(employee = new JMenuItem("Employee"));
master.addSeparator();
master.add(item = new JMenuItem("Item"));
master.add(model = new JMenuItem("Model"));
master.addSeparator();
master.add(exitItem);
MyMenuHandler handler  = new MyMenuHandler(this);
general.addActionListener(handler);
employee.addActionListener(handler);
item.addActionListener(handler);
model.addActionListener(handler);
MyWindowAdapter adapter  = new MyWindowAdapter(this);
addWindowListener(adapter);
KeyStroke ks = KeyStroke.getKeyStroke
(KeyEvent.VK_X,Event.ALT_MASK);
exitItem.setAccelerator(ks);
master.setMnemonic('M');
exitItem.setMnemonic(KeyEvent.VK_X);
mb.add(master); setJMenuBar(mb); }

public static void  main(String args[])
{ Frame f = new FinalMenu();
f.setVisible(true); } }
class MyWindowAdapter extends WindowAdapter
{ FinalMenu mnuFrame;
public MyWindowAdapter(FinalMenu mnuFrame)
{ this.mnuFrame = mnuFrame; }
public void windowClosing(WindowEvent we)
{ System.exit(0); } }
class MyMenuHandler implements ActionListener, ItemListener
{ FinalMenu mnuFrame;
public MyMenuHandler(FinalMenu mnuFrame)
{ this.mnuFrame = mnuFrame; }
public void actionPerformed(ActionEvent ae)
{ String arg = (String)ae.getActionCommand();
if (arg.equals("General"))
System.out.println("Want to call  the general  Master Form"); }
public void itemStateChanged(ItemEvent ie)
{ mnuFrame.repaint(); } }

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Problem in Swings Or get search suggestion and latest updates.


Tagged: