简易记事本界面

 1 package Layout;
 2 import java.awt.*;
 3 import javax.swing.*;
 4 public class NotePad extends JFrame{
 5 JMenuBar cd = new JMenuBar();  //菜单面板
 6 
 7 JMenu cd1 = new JMenu("文件(F)");
 8 JMenu cd2 = new JMenu("选项");  //菜单
 9 JMenu cd3 = new JMenu("视图");
10 JMenu cd4 = new JMenu("帮助");
11 
12 JMenu c1 = new JMenu("新建"); //二级菜单
13 JMenu c2 = new JMenu("打开");
14 JMenu c3 = new JMenu("保存");
15 
16 JMenuItem cdi1 = new JMenuItem("project",new ImageIcon("photo/psb.jpg"));//加图片表示选项前图形图标
17 JMenuItem cdi2 = new JMenuItem("package");//     最低级  无下级菜单选项 
18 JMenuItem cdi3 = new JMenuItem("class");
19 
20 JToolBar gjt = new JToolBar();//     工具条
21 JButton b1 = new JButton();
22 JButton b2 = new JButton();
23 JButton b3 = new JButton();
24 
25 JTextArea wby = new JTextArea(100,400);
26 JScrollPane gdt = new JScrollPane(wby); //滚动条
27 public NotePad(){
28     cd1.setMnemonic('F');       //Alt+F 选中按钮
29     c1.add(cdi1);  
30     c1.add(cdi2);    c1.add(cdi3);    
31     cd1.add(c1);   cd1.addSeparator();  //按钮下加横线  分割
32     cd1.add(c2);cd1.add(c3);
33     cd.add(cd1);cd.add(cd2);cd.add(cd3);cd.add(cd4);
34     this.setJMenuBar(cd);
35     
36     b1.setToolTipText("新建");//  按钮提示信息
37     b2.setToolTipText("打开");
38     b3.setToolTipText("保存");
39     gjt.add(b1);gjt.add(b2);gjt.add(b3);
40     this.add(gjt,BorderLayout.NORTH);
41     
42     wby.setVisible(true); 
43     this.add(wby);//  默认中部
44     
45     this.setTitle("记事本");
46     this.setSize(500, 400);
47     this.setLocation(100, 100);
48     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
49   //  this.setResizable(false);
50     this.setVisible(true);
51 }
52     public static void main(String[] args) {
53      new NotePad();        
54 
55     }
56 
57 }
原文地址:https://www.cnblogs.com/the-wang/p/6752920.html