I can add the ActionListener to JMenu but has no effect. The JMenu
inherits the addActionListener method from AbstractButton which means I can
register an ActionListener to JMenu itself. By looking at the code in
AbstractButton class it seems to me you are adding the ActionListerner
objects into the wrong field which is named "listenerList" instead of
actionListener field.
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
import java.awt.event.*;
import java.awt.*;
public class MenuTest extends JFrame
{
public static void main(String[] args)
{
MenuTest mt = new MenuTest();
JMenuBar mb = new JMenuBar();
JMenu m = new JMenu("File");
//inner class
m.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt)
{ System.out.println("Actionevent " + evt);
}
});
mb.add(m);
mt.setJMenuBar(mb);
mt.setSize(500, 500);
mt.setVisible(true);
}
}
nasser.nouri@Corp 1998-02-02