menuoverview.java
来自「java编程开发技巧与实例的编译测试通过的所有例程」· Java 代码 · 共 61 行
JAVA
61 行
import java.awt.event.*;
import javax.swing.*;
public class MenuOverview extends JFrame implements ActionListener
{
JMenuItem fileOpen = new JMenuItem("Open", new ImageIcon("./Icons/open.gif"));
JMenuItem fileSave = new JMenuItem("Save", new ImageIcon("./Icons/save.gif"));
JMenuItem fileExit = new JMenuItem("Exit", new ImageIcon("./Icons/exit.gif"));
JCheckBoxMenuItem toolView = new JCheckBoxMenuItem("View Tools");
JRadioButtonMenuItem toolConverts = new JRadioButtonMenuItem("Convert Hyperlinks");
JRadioButtonMenuItem toolDisplays = new JRadioButtonMenuItem("Display Hyperlinks", true);
JLabel status = new JLabel("This is a status bar to show the events");
public MenuOverview()
{
super("Menu Overview");
JMenu file = new JMenu("File");
JMenu tools = new JMenu("Tools");
file.add("fileOpen");
fileOpen.addActionListener(this);
file.add("fileSave");
fileSave.addActionListener(this);
file.add(new JSeparator());
file.add(fileExit);
fileExit.addActionListener(this);
tools.add(toolView);
toolView.addActionListener(this);
JMenu toolLinks = new JMenu("Links . . .");
toolLinks.add(toolConverts);
toolConverts.addActionListener(this);
toolLinks.add(toolDisplays);
toolDisplays.addActionListener(this);
tools.add(toolLinks);
JMenuBar menu = new JMenuBar();
menu.add(file);
menu.add(tools);
getContentPane().add(status);
setJMenuBar(menu);
validate();
pack();
setSize(700, 300);
setLocationRelativeTo(null);
setVisible(true);
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource() == fileExit)
System.exit(0);
else
status.setText("Command: " + ae.getActionCommand());
}
public static void main(String args[])
{
MenuOverview mo = new MenuOverview();
mo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?