I'm stuck on an assignment question (studying at 31, crazy I know!)
The problem is this (there will be others!)
I have a JMenuBar with 4 JMenus in it. Each JMenu has some JMenuItems. I need to add ActionListeners to each menu item so that I can make them do something when clicked. For now I just want the Exit menu item to close the application, but it does nothing. Here is my code-
Constructor with code to create the menu
public M257DrawingApplication(String title)
{
super(title);
setSize(FRAME_WIDTH, FRAME_HEIGHT);
this.setResizable(false);
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar mb = new JMenuBar();
JMenu m1 = new JMenu("Style");
JMenu m2 = new JMenu("Size");
JMenu m3 = new JMenu("Colour");
JMenu m4 = new JMenu("Close");
m1.add(new JMenuItem("Courier New"));
m1.add(new JMenuItem("Courier New"));
m1.add(new JMenuItem("Courier New"));
m2.add(new JMenuItem("16"));
m2.add(new JMenuItem("18"));
m2.add(new JMenuItem("20"));
m3.add(new JMenuItem("Blue"));
m3.add(new JMenuItem("Red"));
m3.add(new JMenuItem("Green"));
m4.add(new JMenuItem("Exit"));
mb.add(m1);
mb.add(m2);
mb.add(m3);
mb.add(m4);
setJMenuBar(mb);
Adding an ActionListener to m4(the Close menu)
m4.addActionListener(mw);
My inner ActionListener class
public class MenuWatcher implements ActionListener
{
public MenuWatcher()
{
super();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == "Exit")
{
System.exit(1);
}
}
}
I cant figure out what I'm doing wrong.
All advice will be much appreciated.
Thanks..

New Topic/Question
Reply



MultiQuote





|