控制台程序。
JMenuBar对象表示放在窗口顶部的菜单栏。可以为JMenuBar对象添加JMenu或JMenuItem对象,它们都显示在菜单栏上。JMenu对象是带有标签的菜单,单击就可以显示一列菜单项。JMenuItem对象表示菜单中带有标签的菜单项,单击就会执行某个程序动作。
// Main window for the Sketcher application
import javax.swing.*;
import static java.awt.event.InputEvent.*; // For modifier constants
@SuppressWarnings("serial")
public class SketcherFrame extends JFrame {
// Constructor
public SketcherFrame(String title) {
setTitle(title); // Set the window title
setDefaultCloseOperation(EXIT_ON_CLOSE);
setJMenuBar(menuBar); // Add the menu bar to the window
JMenu fileMenu = new JMenu("File"); // Create File menu
JMenu elementMenu = new JMenu("Elements"); // Create Elements menu
fileMenu.setMnemonic('F'); // Create shortcut
elementMenu.setMnemonic('E'); //