I think u might be getting "invalid method declaration" ERROR.
The problem is in Inner class "MyMenuHandler".
In this class,
public MyWindowAdapter (FinalMenu mnuFrame) is treated as method. and
this method have no return type. that why it show error.
Also, the way u have implemented ut class, It will not compile, even
if u replace "MyWindowAdapter " with "MyMenuHandler" in the above
method(which will make it constructor). This because of circular
dependency. Move ur inner classes out of class "FinalMenu". look at
following 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);
// class MyWindowAdapter
// extends WindowAdapter {
// FinalMenu mnuFrame;
// public MyWindowAdapter(FinalMenu mnuFrame) {
// this.mnuFrame = mnuFrame;
// }
//
// public void windowClosing(WindowEvent we) {
// mnuFrame.setVisible(false);
// }
// }
//
// 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();
// }
// }
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) {
mnuFrame.setVisible(false);
}
}
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();
}
}