欢迎来到天天文库
浏览记录
ID:37857571
大小:68.50 KB
页数:7页
时间:2019-06-01
《Java记事本代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、程序源代码://记事本importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Container;importjava.awt.FlowLayout;importjava.awt.Font;importjava.awt.Graphics;importjava.awt.Toolkit;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;imp
2、ortjava.awt.event.WindowEvent;importjava.io.File;importjava.io.FileInputStream;importjava.io.FileOutputStream;importjava.io.InputStream;importjavax.swing.AbstractAction;importjavax.swing.Action;importjavax.swing.JButton;importjavax.swing.JFileChooser;importjavax.swing.JFrame;importjav
3、ax.swing.JLabel;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JPasswordField;importjavax.swing.JTextField;importjavax.swing.JTextPane;importjavax.swing.JToolBar;importjavax.swing.border.MatteBorder;importjavax.swing.text.DefaultEditorKit.CopyAction;importjavax.s
4、wing.text.DefaultEditorKit.CutAction;importjavax.swing.text.DefaultEditorKit.PasteAction;importjavax.swing.text.DefaultStyledDocument;publicclassEditorDemoextendsJFrame{JTextPanetextPane=newJTextPane();//文本窗格,编辑窗口JLabelstatusBar=newJLabel();//状态栏JFileChooserfilechooser=newJFileChooser
5、();//文件选择器publicEditorDemo(){//构造函数super("简易记事本");//调用父类构造函数Action[]actions=//Action数组,各种操作命令{newNewAction(),newOpenAction(),newSaveAction(),newCutAction(),newCopyAction(),newPasteAction(),newAboutAction(),newExitAction(),};setJMenuBar(createJMenuBar(actions));//设置菜单栏Containercontaine
6、r=getContentPane();//得到容器container.add(createJToolBar(actions),BorderLayout.NORTH);//增加工具栏container.add(textPane,BorderLayout.CENTER);//增加文本窗格container.add(statusBar,BorderLayout.SOUTH);//增加状态栏setSize(500,400);//设置窗口尺寸//setVisible(true);//设置窗口可视setDefaultCloseOperation(JFrame.EXIT_ON_
7、CLOSE);//关闭窗口时退出程序}privateJMenuBarcreateJMenuBar(Action[]actions){//创建菜单栏JMenuBarmenubar=newJMenuBar();//实例化菜单栏JMenumenuFile=newJMenu("文件(F)");//实例化菜单JMenumenuEdit=newJMenu("编辑(E)");JMenumenuFormat=newJMenu("格式(O)");JMenumenuFind=newJMenu("查找(V)");JMenumenuAbout=newJMenu("帮助(H)");menu
8、File.
此文档下载收益归作者所有