-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: el35337 Date: 05/18/98
1. Create a menu item with a shortcut.
2. In actionPerformed, attempt to use the getActionCommand() on the event.
3. If the MenuItem is activated via mouse, no problem.
4. If the MenuItem is activated via shortcut key, call to getActionCommand() throws NullPointerException.
import java.awt.*;
import java.awt.event.*;
public class FooBar extends Frame implements ActionListener
{
public static void main(String[] args)
{
FooBar f = new FooBar();
f.pack();
f.show();
}
public FooBar()
{
MenuBar mb = new MenuBar();
Menu m = new Menu("File");
MenuShortcut ms = new MenuShortcut((int) "O".charAt(0));
MenuItem mi = new MenuItem("Open", ms);
mi.addActionListener(this);
m.add(mi);
mb.add(m);
setMenuBar(mb);
}
public void actionPerformed(ActionEvent e)
{
// Here's the problem. If I click on Open,
// I get the expected response. If I use the
// shortcut, I get a NullPointerException due to
// the call to getActionCommand.
if (e.getActionCommand().equals("Open"))
{
System.out.println("Yeah, I'll think about it");
}
}
}
(Review ID: 30098)
======================================================================
- duplicates
-
JDK-4079449 MenuItem objects return null if they are activated by shortcut
-
- Resolved
-