本文整理汇总了Java中javax.swing.JMenuItem.getActionCommand方法的典型用法代码示例。如果您正苦于以下问题:Java JMenuItem.getActionCommand方法的具体用法?Java JMenuItem.getActionCommand怎么用?Java JMenuItem.getActionCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JMenuItem
的用法示例。
在下文中一共展示了JMenuItem.getActionCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import javax.swing.JMenuItem; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {
JMenuItem target = (JMenuItem)e.getSource();
String actionCommand = target.getActionCommand();
try {
if (actionCommand.equals("Open")) {
_open();
} else if (actionCommand.equals("Save")) {
_save();
} else if (actionCommand.equals("SaveAs")) {
_saveAs();
} else if (actionCommand.equals("Export")) {
_export();
} else if (actionCommand.equals("Print")) {
_print();
} else if (actionCommand.equals("Close")) {
_close();
}
} catch (Exception exception) {
// If we do not catch exceptions here, then they
// disappear to stdout, which is bad if we launched
// where there is no stdout visible.
JOptionPane.showMessageDialog(null,
"File Menu Exception:\n" + exception.toString(),
"Ptolemy Plot Error", JOptionPane.WARNING_MESSAGE);
}
// NOTE: The following should not be needed, but there jdk1.3beta
// appears to have a bug in swing where repainting doesn't
// properly occur.
repaint();
}