您好,我试图从事件侦听器中启用我的 JMenuItem,但它似乎超出了范围。我是 Java 新手,所以我将如何正确处理这个问题。所述事件侦听器将更改为新视图并启用禁用的菜单项。
//Create and add MenuItems
JMenuItem fileItem0 = new JMenuItem("Load");
collMenu.add(fileItem0);
JMenuItem fileItem1 = new JMenuItem("Add");
fileItem1.setEnabled(false);
collMenu.add(fileItem1);
JMenuItem fileItem2 = new JMenuItem("Delete");
fileItem2.setEnabled(false);
collMenu.add(fileItem2);
//Add Menu bar to frame
menubar.add(collMenu);
//Menu Item Functions
fileItem0.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JOptionPane.showMessageDialog(null,"You selected: Load.");
//Enable fileitem1 & 2 here ??
}
});