java 记事本---《功能虽然不是很齐…

package Notepad;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.filechooser.FileFilter;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import javax.swing.undo.UndoManager;
import javax.swing.text.*;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent;
 public class NoteBook{
    publicstatic void main(String []args){
     new Notepad();
     }
 }
 class Notepad extends JFrame implementsActionListener{
  private JOptionPane jo;
  private File currentFile =null;
  private JTextArea jta;
  private JScrollPane js;
  private JMenuBar menubar;
  private JMenumenu  ;
  private JMenu menuB ;
  private JMenuItem New;
  private JMenuItem open ;
  private JMenuItem save ;
  private JMenuItem exit ;
  private JMenuItem saveas;
  private JToolBar toolbar;//工具栏
  private JMenuItem cut ;
  private JMenuItem copy ;
  private JMenuItem paste ;
  private JMenuItem all ;
  private JMenuItem back ;
  private JToggleButtonbtnopen;
  private JToggleButtonbtnnew;
  private JToggleButtonbtnpaste;
  private JToggleButtonbtncopy;
  private JToggleButtonbtncut;
  private JToggleButtonbtnsave;
  private JToggleButtonbtnsaveas;
  private UndoManager undomang;//定义一个撤销控件
  private boolean change;
  private boolean openflag;
  private boolean newflag;
  private boolean exitflag;
   private booleanwindowflag;
  private int num;
  private Document doc;
  Container cp;
   public voidinit(){
       undomang=new  UndoManager();
    menubar = new JMenuBar();//创建菜单栏
    toolbar = new JToolBar();
    menuB  = new JMenu("编辑");
    menu  = new JMenu("文件");//创建菜单
    New = new JMenuItem("新建",new ImageIcon("new.gif"));//创建子菜单
    open = new JMenuItem("打开",new ImageIcon("open.gif"));
    save= new JMenuItem("保存",new ImageIcon("save.gif"));
    exit = new JMenuItem("退出");
    saveas = new JMenuItem("另存为",new ImageIcon("save.gif"));
    cut = new JMenuItem("剪切",new ImageIcon("cut.gif"));
    copy = new JMenuItem("复制",new ImageIcon("copy.gif"));
    paste = new JMenuItem("粘贴",new ImageIcon("paste.gif"));
    back = new JMenuItem("撤销");
    all = new JMenuItem("全选");
    btnopen = new JToggleButton(new ImageIcon("open.gif"));
    btnnew = new JToggleButton(new ImageIcon("new.gif"));
    btncopy = new JToggleButton(new ImageIcon("copy.gif"));
    btnpaste = new JToggleButton(new ImageIcon("paste.gif"));
    btnsave = new JToggleButton(new ImageIcon("save.gif"));
    btncut = new JToggleButton(new ImageIcon("cut.gif"));
    btnsaveas = new JToggleButton(new ImageIcon("save.gif"));
    jta = new JTextArea(30,50);
    js = new JScrollPane(jta);//为JTextArea添加滚动条
    doc = jta.getDocument();//获得文本中的内容
    doc.addUndoableEditListener(undomang);//添加事件监听
    menu.add(New);//向文件添加子菜单
    menu.add(open);
    menu.add(save);
    menu.add(saveas);
    menu.insertSeparator(3);//插入横线
    menu.add(exit);
    menuB.add(cut);
    menuB.add(copy);
    menuB.add(paste);
    menuB.insertSeparator(3);
    menuB.add(all);
    menuB.add(back);
    

你可能感兴趣的:(java)