java 菜单

 1 package test;
 2 
 3 import java.awt.Container;
 4 import java.awt.GridLayout;
 5 import java.awt.event.WindowAdapter;
 6 import java.awt.event.WindowEvent;
 7 import java.io.File;
 8 import java.util.Vector;
 9 
10 import javax.swing.BorderFactory;
11 import javax.swing.ComboBoxEditor;
12 import javax.swing.ImageIcon;
13 import javax.swing.JCheckBox;
14 import javax.swing.JComboBox;
15 import javax.swing.JFrame;
16 import javax.swing.JLabel;
17 import javax.swing.JMenu;
18 import javax.swing.JMenuBar;
19 import javax.swing.JMenuItem;
20 import javax.swing.JPanel;
21 import javax.swing.JRadioButton;
22 import javax.swing.JScrollPane;
23 import javax.swing.JTextArea;
24 import javax.swing.KeyStroke;
25 public class test {
26     public static void main(String[] args) {
27         JFrame f=new JFrame("Welcome!");
28         JTextArea text=new JTextArea();
29         text.setEditable(true);
30         f.getContentPane().add(new JScrollPane(text));
31         JMenu menuFile=new JMenu("FILE");
32         menuFile.setIcon(new ImageIcon("d:"+File.separator+"Note.png"));
33         JMenuBar menuBar=new JMenuBar();
34         JMenuItem newItem=new JMenuItem("New",new ImageIcon("d:"+File.separator+"New.png"));
35         JMenuItem openItem=new JMenuItem("Open",new ImageIcon("d:"+File.separator+"Open.png"));
36         JMenuItem closeItem=new JMenuItem("Close",new ImageIcon("d:"+File.separator+"Close.png"));
37         JMenuItem exitItem=new JMenuItem("Exit",new ImageIcon("d:"+File.separator+"Exit.png"));
38         newItem.setMnemonic('N');
39         openItem.setMnemonic('O');
40         closeItem.setMnemonic('C');
41         exitItem.setMnemonic('E');
42         newItem.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
43         openItem.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));
44         closeItem.setAccelerator(KeyStroke.getKeyStroke('C',java.awt.Event.ALT_MASK));
45         exitItem.setAccelerator(KeyStroke.getKeyStroke('E',java.awt.Event.ALT_MASK));
46         menuFile.add(newItem);
47         menuFile.add(openItem);
48         menuFile.add(closeItem);
49         menuFile.add(exitItem);
50         menuBar.add(menuFile);
51         f.addWindowListener(new WindowAdapter(){
52             public void windowClosing(WindowEvent arg0){
53                 System.exit(1);
54             }
55         });
56         f.setJMenuBar(menuBar);
57         f.setVisible(true);
58         f.setSize(300,180);
59         f.setLocation(300,200);
60         
61     }
62 
63 
64 }

 

你可能感兴趣的:(java 菜单)