标签:java exit tor 实验代码 图片 ext 文件选择 mon listen
个人思考总结:`菜单项JMenultem`是加入`菜单JMenu`上,而`菜单JMenu`汇总在`菜单栏JMenuBar`上.
package 第十三周;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Book extends JFrame // 记事本界面
{
JMenuBar cd; // 菜单面板(菜单栏)
JMenu cd1, cd2, cd3, cd4, cd5; // 菜单
JMenuItem cdx2, cdx3, cdx4, cdx5, cdx6, cdx7; // 菜单项
JMenu ej;
JMenuItem ej1, ej2;
JToolBar gjt; // 工具条
JButton an1, an2, an3, an4, an5, an6;
JTextArea wby;
JScrollPane gdt;
public static void main(String[] args)
{
Book lx = new Book();
}
Book()
{
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(""));
ej2 = new JMenuItem("图片");
cdx2 = new JMenuItem("打开", new ImageIcon(""));
cdx3 = new JMenuItem("保存(s)", new ImageIcon(""));
cdx3.setMnemonic('S');
cdx4 = new JMenuItem("另存为", new ImageIcon(""));
cdx5 = new JMenuItem("页面设置", new ImageIcon(""));
cdx6 = new JMenuItem("打印", new ImageIcon(""));
cdx7 = new JMenuItem("退出", new ImageIcon(""));
wby = new JTextArea();
gdt = new JScrollPane(wby);
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);
cd.add(cd1);
cd.add(cd2);
cd.add(cd3);
cd.add(cd4);
cd.add(cd5);
this.setJMenuBar(cd);
ImageIcon tp1 = new ImageIcon("");
this.setIconImage(tp1.getImage());
this.setTitle("清悠灬音辰 —— 记事本");
this.setSize(570, 370);
this.setLocation(300, 280);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
标签:java exit tor 实验代码 图片 ext 文件选择 mon listen
原文地址:https://www.cnblogs.com/youlanghua/p/11918968.html