Java记事本源代码(完整)

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/**

* 作品:记事本

* 作者:***

* 功能:简单的文字编辑

*/

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

import javax.swing.event.ChangeEvent;

import javax.swing.event.ChangeListener;

class NotePad extends JFrame{

private JMenuBar menuBar;

private JMenu fielMenu,editMenu,formMenu,aboutMenu;

private JMenuItem

newMenuItem,openMenuItem,saveMenuItem,exitMenuItem;

private JMenuItem

cutMenuItem,copyMenuItem,pasteMenuItem,foundItem,replaceItem,s electAll;

private JMenuItem font,about;

private JTextArea textArea;

private JFrame foundFrame,replaceFrame;

private JCheckBoxMenuItem wrapline;

private JTextField textField1=new JTextField(15);

private JTextField textField2=new JTextField(15);

private JButton startButton,replaceButton,reallButton;

int start=0;

String value;

File file=null;

JFileChooser fileChooser=new JFileChooser();

boolean wrap=false;

public NotePad(){

//创建文本域

textArea=new JTextArea();

add(new JScrollPane(textArea),BorderLayout.CENTER);

//创建文件菜单及文件菜单项

fielMenu=new JMenu("文件");

fielMenu.setFont(new Font("微软雅黑",0,15));

newMenuItem=new JMenuItem("新建",new

ImageIcon("icons\\new24.gif"));

newMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));

newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_N,InputEvent.CTRL_MASK));

newMenuItem.addActionListener(listener);

openMenuItem=new JMenuItem("打开",new

ImageIcon("icons\\open24.gif"));

openMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));

openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_O,InputEvent.CTRL_MASK));

openMenuItem.addActionListener(listener);

saveMenuItem=new JMenuItem("保存",new

ImageIcon("icons\\save.gif"));

saveMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));

saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_S,InputEvent.CTRL_MASK));

saveMenuItem.addActionListener(listener);

exitMenuItem=new JMenuItem("退出",new

ImageIcon("icons\\exit24.gif"));

exitMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));

exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_E,InputEvent.CTRL_MASK));

exitMenuItem.addActionListener(listener);

//创建编辑菜单及菜单项

editMenu=new JMenu("编辑");

editMenu.setFont(new Font("微软雅黑",0,15));

cutMenuItem=new JMenuItem("剪切",new

ImageIcon("icons\\cut24.gif"));

cutMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));

cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_X,InputEvent.CTRL_MASK));

cutMenuItem.addActionListener(listener);

copyMenuItem=new JMenuItem("复制",new

ImageIcon("icons\\copy24.gif"));

相关文档
最新文档