⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menuoverview.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:

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");
  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();
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -