/**
* 作品:记事本
* 作者:***
* 功能:简单的文字编辑
*/
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,selectAll;
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(newnotepad++ 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"));
copyMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));
copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));
copyMenuItem.addActionListener(listener);
pasteMenuItem=new JMenuItem("粘贴",new ImageIcon("icons\\paste24.gif"));
pasteMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));
pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));
pasteMenuItem.addActionListener(listener);
foundItem=new JMenuItem("查");
foundItem.setFont(new Font("微软雅黑",Font.BOLD,13));
foundItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTR
L_MASK));
foundItem.addActionListener(listener);
replaceItem=new JMenuItem("替换");
replaceItem.setFont(new Font("微软雅黑",Font.BOLD,13));
replaceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,InputEvent.CTRL_MASK));
replaceItem.addActionListener(listener);
selectAll=new JMenuItem("全选");
selectAll.setFont(new Font("微软雅黑",Font.BOLD,13));
selectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
selectAll.addActionListener(listener);
//创建格式菜单及菜单项
formMenu=new JMenu("格式");
formMenu.setFont(new Font("微软雅黑",0,15));
wrapline=new JCheckBoxMenuItem("自动换行");
wrapline.setFont(new Font("微软雅黑",Font.BOLD,13));
wrapline.addActionListener(listener);
wrapline.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
if(wrapline.isSelected()){
textArea.setLineWrap(true);
}
else
textArea.setLineWrap(false);
}
});
font=new JMenuItem("字体");
font.setFont(new Font("微软雅黑",Font.BOLD,13));
font.addActionListener(listener);
//创建关于菜单
aboutMenu=new JMenu("关于");
aboutMenu.setFont(new Font("微软雅黑",0,15));
about=new JMenuItem("记事本……");
about.setFont(new Font("微软雅黑",Font.BOLD,13));
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论