好象是可以的。。我试了下:
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
class MyJFrame extends JFrame
{
private JMenuBar menuBar;
private JMenu fileMenu;
private JMenu editMenu;
public MyJFrame()
{
menuBar = new JMenuBar();
fileMenu = new JMenu("File");
editMenu = new JMenu("Edit");
fileMenu.addMenuListener(new MyMenuListener());
fileMenu.setMnemonic(KeyEvent.VK_A);
this.setJMenuBar(menuBar);
menuBar.add(fileMenu);
menuBar.add(editMenu);
this.setVisible(true);
this.setSize(300, 300);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
private class MyMenuListener
implements MenuListener
{
public void menuSelected(MenuEvent e)
{
System.out.println("111");
}
public void menuDeselected(MenuEvent e)
{}
public void menuCanceled(MenuEvent e)
{}
}
}
public class TestJMenu
{
public static void main(String [] args)
{
MyJFrame mjf = new MyJFrame();
}
}
按了ALT+A是有输出的