package gui1; import java.awt.BorderLayout; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JToolBar; public class jishiben extends JFrame{ JMenuBar cd;//菜单面板 JMenu cd1,cd2,cd3,cd4,cd5;//菜单 JMenuItem cdx2,cdx3,cdx4,cdx5,cdx6,cdx7; JMenu ej;JMenuItem ej1,ej2; //JMenuItem是最终的,不可以有下一级菜单。直接响应应用 //JMenu 不是最最终的,点击后出现下一级 JToolBar jtb;//工具条 JButton jb1,jb2,jb3,jb4,jb5,jb6; JTextArea jta; JScrollPane jsp; public static void main(String[] args) { // TODO Auto-generated method stub jishiben js1=new jishiben(); } public jishiben() { //工具条 jtb=new JToolBar(); jb1=new JButton(new ImageIcon("image/264.jpg")); jb1.setToolTipText("新建"); jb2=new JButton(new ImageIcon("image/264.jpg")); jb2.setToolTipText("打开"); jb3=new JButton(new ImageIcon("image/264.jpg")); jb3.setToolTipText("保存"); jb4=new JButton(new ImageIcon("image/264.jpg")); jb4.setToolTipText("剪切"); jb5=new JButton(new ImageIcon("image/264.jpg")); jb5.setToolTipText("复制"); jb6=new JButton(new ImageIcon("image/264.jpg")); jb6.setToolTipText("粘贴"); //菜单 cd=new JMenuBar(); cd1=new JMenu("文件(F)"); cd1.setMnemonic('F'); cd2=new JMenu("编辑(E)"); cd2.setMnemonic('E'); cd3=new JMenu("格式(O)"); cd3.setMnemonic('O'); cd4=new JMenu("查看(V)"); cd4.setMnemonic('V'); cd5=new JMenu("帮助(H)"); cd5.setMnemonic('H'); //菜单项 ej=new JMenu("新建"); ej1=new JMenuItem("文件",new ImageIcon("image/263.jpg")); ej2=new JMenuItem("模板"); cdx2=new JMenuItem("打开",new ImageIcon("image/263.jpg")); cdx3=new JMenuItem("保存",new ImageIcon("image/263.jpg")); cdx4=new JMenuItem("另存为",new ImageIcon("image/263.jpg")); cdx5=new JMenuItem("页面设置",new ImageIcon("image/263.jpg")); cdx6=new JMenuItem("打印",new ImageIcon("image/263.jpg")); cdx7=new JMenuItem("退出",new ImageIcon("image/263.jpg")); jta=new JTextArea(); jsp=new JScrollPane(jta); ej.add(ej1); ej.add(ej2); cd1.add(ej); cd1.add(cdx2);cd1.add(cdx3);cd1.add(cdx4);cd1.addSeparator(); cd1.add(cdx5);cd1.add(cdx6);cd1.addSeparator();//添加分割线 cd1.add(cdx7); jtb.add(jb1);jtb.add(jb2);jtb.add(jb3); jtb.add(jb4);jtb.add(jb5);jtb.add(jb6); cd.add(cd1);cd.add(cd2);cd.add(cd3);cd.add(cd4);cd.add(cd5); this.setJMenuBar(cd);//菜单栏不计入布局 this.add(jtb,BorderLayout.NORTH); this.add(jsp);//默认添加到中间 this.setTitle("记事本"); this.setSize(400,320); this.setLocation(100, 180); this.setIconImage((new ImageIcon("image/23.jpg")).getImage());//(new ImageIcon("")).getImage() this.setResizable(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } }