Java写了个记事本

来源:互联网 发布:怎么删除淘宝上的好评 编辑:程序博客网 时间:2024/05/01 04:16
package Rong;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.PrintJob;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;


public class Notepad extends JFrame implementsActionListener{
    privatestatic final long serialVersionUID = 1L;
    staticString softwarename="С»šŒÇʱŸ";
    Stringversion="Version1.0";
    Stringauthor="»šÐ²ý";
    Stringemail="592409652@qq.com";
    Stringblog="http://hi.baidu.com/huaxinchang/home";
    staticJTextArea textArea;
    JMenuBarmenuBar;
    JLabelstatuslabel;
    JMenufileMenu,editMenu,formatMenu,checkMenu,helpMenu,style;
    JMenuItemcreate,open,save,saveas,pageset,print,exit;
    JMenuItembackout,cut,copy,paste,delete,find,findnext,replace,jumpto,allselect,datetime;
    JMenuItemautoline,font;
    ButtonGroupstyleMenuGroup = new ButtonGroup();
   JRadioButtonMenuItemmetalstyle,windowsstyle,motifstyle;
    JMenuItemstatusbar;
    JMenuItemcheckhelp,about;
    Stringfilename="",filepath="";
    JPopupMenurightMenu;
    JMenuItemcut_r,copy_r,paste_r,allselect_r,delete_r;
    booleanflag=false;
   //×Ô¶¯»»ÐкÍ׎̬Àž
    int a =0;
    intsize=12;//ĬÈÏ×ÖÌåŽóС
   PrintJob printjob=null;//ÉùÃ÷Ò»žöÒªŽòÓ¡µÄ¶ÔÏó
   Graphics graphics=null;//ÒªŽòÓ¡µÄ¶ÔÏó
    Datenowdate;//¶šÒåÒ»žöʱŒä¶ÔÏó
   SimpleDateFormat sdf;
    SearchFramesearch=null;
    AboutDialogaboutDialog = null; //¹ØÓÚ¶Ô»°¿ò
   AboutNotepadDialog aboutNotepad=newAboutNotepadDialog();
    ImageIconicon= null; //±Ÿ³ÌÐòÍŒ±ê
    publicNotepad() {
      super(softwarename);
      setIconImage((newImageIcon(getClass().getResource("star.png"))).getImage());
      //ÓÃÀŽÉèÖÃŽ°¿ÚËæÆÁÄ»ŽóСžÄ±ä
      sizeWindowOnScreen(this, 0.6, 0.6);
      //ÉèÖÃŽ°¿ÚÔÚÆÁÄ»ÉÏŸÓÖÐÏÔÊŸ
      int W = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
      int H = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
      this.setLocation((W-this.getWidth())/2,(H-this.getHeight())/2);
      textArea=new MyTextArea();
      //Æô¶¯ÎıŸÓòµÄÍÏ·ÅÖ§³Ö
      textArea.setDragEnabled(true);
      Container c =this.getContentPane();            
      //ŽŽœš¹ö¶¯Ìõ¶ÔÏó
      JScrollPane scrollPane = new JScrollPane();
      scrollPane.setViewportView(textArea);
      //ÐèҪʱÏÔʟˮƜ¹ö¶¯Öá
      scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      //×ÜÊÇÏÔÊŸŽ¹Ö±¹ö¶¯Öá
      scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
      c.add(scrollPane);
      this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//ÉèÖÃĬÈϹرշœÊœ   
      this.setVisible(true);//ÉèÖÃŽ°¿Ú¿ÉŒûÐÔ
            
      //"ÎÄŒþ"²Ëµ¥Œ°Æä×Ӳ˵¥
      fileMenu = new JMenu("ÎÄŒþ");
      create=new JMenuItem("ÐÂœš");
      create.addActionListener(this);
      open=new JMenuItem("Žò¿ª");
      open.addActionListener(this);
      save=new JMenuItem("±£Žæ");
      save.addActionListener(this);
      saveas=new JMenuItem("ÁíŽæΪ");
      saveas.addActionListener(this);
      pageset=new JMenuItem("Ò³ÃæÉèÖÃ");
      pageset.addActionListener(this);
      print=new JMenuItem("ŽòÓ¡");
      print.addActionListener(this);
      exit=new JMenuItem("Í˳ö");
      exit.addActionListener(this);
      fileMenu.add(create);
      fileMenu.addSeparator();
      fileMenu.add(open);
      fileMenu.addSeparator();
      fileMenu.add(save);
      fileMenu.addSeparator();
      fileMenu.add(saveas);
      fileMenu.addSeparator();
      fileMenu.add(pageset);
      fileMenu.addSeparator();
      fileMenu.add(print);
      fileMenu.addSeparator();
      fileMenu.add(exit);
      
      //"±àŒ­"²Ëµ¥Œ°Æä×Ӳ˵¥
      editMenu = new JMenu("±àŒ­");
      backout=new JMenuItem("³·Ïú");
      backout.setEnabled(false);
      backout.addActionListener(this);
      cut=new JMenuItem("ŒôÇÐ");
      cut.setEnabled(false);
      cut.addActionListener(this);
      copy=new JMenuItem("žŽÖÆ");
      copy.setEnabled(false);
      copy.addActionListener(this);
      paste=new JMenuItem("Õ³Ìù");
      paste.setEnabled(false);
      paste.addActionListener(this);
      delete=new JMenuItem("ÉŸ³ý");
      delete.setEnabled(false);
      delete.addActionListener(this);
      find=new JMenuItem("²éÕÒ¡­¡­");
      find.setEnabled(false);
      find.addActionListener(this);
      findnext=new JMenuItem("²éÕÒÏÂÒ»žö");
      findnext.setEnabled(false);
      findnext.addActionListener(this);
      replace=new JMenuItem("Ìæ»»¡­¡­");
      replace.setEnabled(false);
      replace.addActionListener(this);
      jumpto=new JMenuItem("תµœ¡­¡­");
      jumpto.setEnabled(false);
      jumpto.addActionListener(this);
      allselect=new JMenuItem("È«Ñ¡");
      allselect.setEnabled(false);
      allselect.addActionListener(this);
      datetime=new JMenuItem("ÈÕÆÚ/ʱŒä");
      datetime.addActionListener(this);
      editMenu.add(backout);
      editMenu.add(cut);
      editMenu.addSeparator();
      editMenu.add(copy);
      editMenu.addSeparator();
      editMenu.add(paste);
      editMenu.addSeparator();
      editMenu.add(delete);
      editMenu.addSeparator();
      editMenu.add(find);
      editMenu.addSeparator();
      editMenu.add(findnext);
      editMenu.addSeparator();
      editMenu.add(replace);
      editMenu.addSeparator();
      editMenu.add(jumpto);
      editMenu.addSeparator();
      editMenu.add(allselect);
      editMenu.addSeparator();
      editMenu.add(datetime);
      
      //"žñÊœ"²Ëµ¥Œ°Æä×Ӳ˵¥
      formatMenu = new JMenu("žñÊœ");
      autoline=new JMenuItem("×Ô¶¯»»ÐÐ");
      autoline.addActionListener(this);
      font=new JMenuItem("×ÖÌå¡­¡­");
      style=new JMenu("œçÃæ·çžñ");
      metalstyle=newJRadioButtonMenuItem("Java·çžñ(ĬÈÏ)");
      metalstyle.addActionListener(this);
      motifstyle=newJRadioButtonMenuItem("Motif·çžñ");
      motifstyle.addActionListener(this);
      windowsstyle=newJRadioButtonMenuItem("Windows·çžñ");
      windowsstyle.addActionListener(this);
      styleMenuGroup.add(metalstyle);
      styleMenuGroup.add(motifstyle);
      styleMenuGroup.add(windowsstyle);
      metalstyle.setSelected(true);
      style.add(metalstyle);
      style.addSeparator();
      style.add(motifstyle);
      style.addSeparator();
      style.add(windowsstyle);
      formatMenu.add(autoline);
      formatMenu.addSeparator();
      formatMenu.add(font);
      formatMenu.addSeparator();
      formatMenu.add(style);
      
      //"²é¿Ž"²Ëµ¥Œ°Æä×Ӳ˵¥
      checkMenu = new JMenu("²é¿Ž");
      statusbar=new JMenuItem("²é¿Ž×ŽÌ¬Àž");
      statusbar.addActionListener(this);
      checkMenu.add(statusbar);
      statuslabel=new JLabel();
      
      //"°ïÖú"²Ëµ¥Œ°Æä×Ӳ˵¥
      helpMenu = new JMenu("°ïÖú");
      checkhelp=new JMenuItem("²é¿Ž°ïÖú");
      checkhelp.addActionListener(this);
      about=new JMenuItem("¹ØÓÚŒÇʱŸ");
      about.addActionListener(this);
      helpMenu.add(checkhelp);
      helpMenu.addSeparator();
      helpMenu.add(about);
      
      //Ôڲ˵¥ÀžÉÏÌíŒÓÒ»Œ¶²Ëµ¥
      menuBar = new JMenuBar();
      menuBar.add(fileMenu);
      menuBar.add(editMenu);
      menuBar.add(formatMenu);
      menuBar.add(checkMenu);
      menuBar.add(helpMenu);      
      this.setJMenuBar(menuBar);//ÌíŒÓ²Ëµ¥Àž
      
      //ÓÒŒü²Ëµ¥
      rightMenu=new JPopupMenu();
      cut_r=new JMenuItem("ŒôÇÐ");
      cut_r.addActionListener(this);
      copy_r=new JMenuItem("žŽÖÆ");
      copy_r.addActionListener(this);
      paste_r=new JMenuItem("Õ³Ìù");
      paste_r.addActionListener(this);
      delete_r=new JMenuItem("ÉŸ³ý");
      delete_r.addActionListener(this);
      allselect_r=new JMenuItem("È«Ñ¡");
      allselect_r.addActionListener(this);
      rightMenu.add(cut_r);
      rightMenu.addSeparator();
      rightMenu.add(copy_r);
      rightMenu.addSeparator();
      rightMenu.add(paste_r);
      rightMenu.addSeparator();
      rightMenu.add(delete_r);
      rightMenu.addSeparator();
      rightMenu.add(allselect_r);
      
      //ÎıŸÇøÓòÌíŒÓÊó±êÊÂŒþŒàÌý
      textArea.addMouseListener(new MouseAdapter(){
         public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
               //ÏÔÊŸÓÒŒü²Ëµ¥
               rightMenu.show(e.getComponent(), e.getX(),e.getY());
               String temp=textArea.getSelectedText();
               if(temp!=null){
                  cut.setEnabled(true);
                  copy.setEnabled(true);
                  delete.setEnabled(true);
                  cut_r.setEnabled(true);
                  copy_r.setEnabled(true);
                  delete_r.setEnabled(true);
               }
               else{
                  cut.setEnabled(false);
                  copy.setEnabled(false);
                  delete.setEnabled(false);
                  cut_r.setEnabled(false);
                  copy_r.setEnabled(false);
                  delete_r.setEnabled(false);
               }
               String text=textArea.getText();
               if(text!=null){
                  find.setEnabled(true);
                  findnext.setEnabled(true);
                  replace.setEnabled(true);
                  jumpto.setEnabled(true);
                  allselect.setEnabled(true);
                  allselect_r.setEnabled(true);
               }
               else{
                  find.setEnabled(false);
                  findnext.setEnabled(false);
                  replace.setEnabled(true);
                  jumpto.setEnabled(false);
                  allselect.setEnabled(false);
                  allselect_r.setEnabled(false);
               }
               String clipboard=getSysClipboardText();
               if(clipboard.equals("")){
                  paste.setEnabled(false);
                  paste_r.setEnabled(false);
               }
               else{
                  paste.setEnabled(true);
                  paste_r.setEnabled(true);
               }
            }
         }
      });
      //×ÖÌå
      JLabel lbfont = new JLabel("×ÖÌå");
      JLabel lbsize = new JLabel("ŽóС");
      JLabel lbshape = new JLabel("×ÖÐÎ");
      JPanel fontPane = new JPanel();
      JPanel sizePane = new JPanel();
      JPanel shapePane = new JPanel();
      JPanel buttonPane = new JPanel();
      final JFrame fontMain = new JFrame();
      fontMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      final JDialog fontJd = new JDialog(fontMain,"×ÖÌå,ÑÕÉ«,µ÷É«°å", true);
      JButton ok = new JButton("È·¶š");
      JButton canel = new JButton("È¡Ïû");
      JButton color = new JButton("ÑÕÉ«");
      final JList fontList = new JList();
      JScrollPane fontScroll=newJScrollPane(fontList);
      fontScroll.setSize(40, 60);
      final JList shapeList = new JList();
      JScrollPane shapeScroll=newJScrollPane(shapeList);
      shapeScroll.setSize(40, 60);
      final JList sizeList = new JList();
      JScrollPane sizeScroll=newJScrollPane(sizeList);
      sizeScroll.setSize(40, 60);

      //ŒÓϵͳ×ÖÌå
      String[] fontNames =GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getAvailableFontFamilyNames();
      fontList.setListData(fontNames);

      // ×ÖÌåÐÎ׎
      String[]shape={"³£¹æ","ŽÖÌå","бÌå","ŽÖбÌå"};
      shapeList.setListData(shape);

      //ÉèÖÃ×ÖÌå¶Ô»°¿ò
      fontJd.setSize(500, 300);
      fontJd.setResizable(false);
      fontPane.add(lbfont);
      fontPane.add(fontScroll);
      sizePane.add(lbsize);
      sizePane.add(sizeScroll);
      shapePane.add(lbshape);
      shapePane.add(shapeScroll);
      buttonPane.setLayout(newFlowLayout(FlowLayout.CENTER, 20, 10));
      buttonPane.add(ok);
      buttonPane.add(canel);
      buttonPane.add(color);

      fontJd.setLayout(newFlowLayout(FlowLayout.CENTER, 10, 10));
      fontJd.add(fontPane);
      fontJd.add(sizePane);
      fontJd.add(shapePane);
      fontJd.add(buttonPane);

      // ÉèÖÃ×ÖÌåŽóС
      String[] fontsize = {"8","9","10","11","12","13","14","16","18","20","22","24","26","28","36","48","72","³õºÅ",
               "С³õ","Ò»ºÅ","Сһ","¶þºÅ","С¶þ","ÈýºÅ","СÈý","ËĺÅ","СËÄ","ÎåºÅ","СÎå","ÁùºÅ","СÁù","ÆߺÅ","°ËºÅ"};
      sizeList.setListData(fontsize);
      
      //ÉèÖóõʌֵ
      fontList.setSelectedIndex(0);
      sizeList.setSelectedIndex(4);
      shapeList.setSelectedIndex(0);

      sizeList.addListSelectionListener(newListSelectionListener(){
         @Override
         public void valueChanged(ListSelectionEvent arg0){
            // TODO Auto-generated method stub
               int index = sizeList.getSelectedIndex();
               if(index<=16)
                  size = Integer.parseInt((String)sizeList.getSelectedValue());
               switch(index){
                   case 17: size = 100;break;
                   case 18: size = 90;break;
                   case 19: size = 80;break;
                   case 20: size = 60;break;
                   case 21: size = 50;break;
                   case 22: size = 40;break;
                   case 23: size = 30;break;
                   case 24: size = 20;break;
                   case 25: size = 18;break;
                   case 26: size = 16;break;
                   case 27: size = 12;break;
                   case 28: size = 11;break;
                   case 29: size = 9;break;
                   case 30: size = 8;break;
                   case 31: size =7;break;                
                 
                 
      });
      
      //×ÖÌåŒàÌýÆ÷
      font.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
            fontJd.setLocationRelativeTo(Notepad.this);
            fontJd.setVisible(true);
            int style = 0;
            if (shapeList.getSelectedValue().equals("³£¹æ")){
               style = Font.PLAIN;
            }
            if (shapeList.getSelectedValue().equals("бÌå")){
               style = Font.ITALIC;
            }
            if (shapeList.getSelectedValue().equals("ŽÖÌå")){
               style = Font.BOLD;
            }
            if(shapeList.getSelectedValue().equals("ŽÖбÌå")) {
               style = Font.BOLD + Font.ITALIC;
            }
            Font f=newFont(String.valueOf(fontList.getSelectedValue()),style,size);
            textArea.setFont(f);
            fontJd.dispose();
         }
      });
      // ÉèÖÃÑÕÉ«°ŽÅ¥ŒàÌýÆ÷
      color.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
            Color fcolor = textArea.getForeground();
            textArea.setForeground(JColorChooser.showDialog(textArea,"Ñ¡Ôñ×ÖÌåÑÕÉ«", fcolor));
         }
      });

      // È¡Ïû°ŽÅ¥ŒàÌýÆ÷
      canel.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e){
            fontMain.dispose();
         }
      });

      // È·¶š°ŽÅ¥ŒàÌýÆ÷
      ok.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e){
            fontMain.dispose();
         }
      });

      //ÎĵµžÄ±äÊÂŒþ
      textArea.getDocument().addDocumentListener(newDocumentListener(){
         @Override
         public void changedUpdate(DocumentEvent arg0){
            // TODO Auto-generated method stub
            flag=true;
         }
         @Override
         public void insertUpdate(DocumentEvent arg0){
            // TODO Auto-generated method stub
            flag=true;
         }
         @Override
         public void removeUpdate(DocumentEvent arg0){
            // TODO Auto-generated method stub
            flag=true;
                 
      });
      //Ž°¿ÚŒàÌýÆ÷
      this.addWindowListener(new WindowAdapter(){
         public void windowClosing(WindowEvent w) {
            filename = Notepad.this.getTitle();
            if(flag == true) {
               int returnValue =JOptionPane.showConfirmDialog(null,
                     Notepad.this.getTitle() +"ÎÄŒþ»¹Ã»Óб£Žæ£¡ÐèÒª±£Žæ£¿", "ŒÇʱŸ",
                     JOptionPane.YES_NO_CANCEL_OPTION);
               if (returnValue == JOptionPane.YES_OPTION){
                  save_asMethod();
               }
               else if(returnValue == JOptionPane.NO_OPTION){
                  System.exit(0);
               }
               else{
                  setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
               }
            }
         }
      });
      // ¿ìœÝŒü
      open.setAccelerator(KeyStroke.getKeyStroke('O',InputEvent.CTRL_MASK));
      create.setAccelerator(KeyStroke.getKeyStroke('N',InputEvent.CTRL_MASK));
      save.setAccelerator(KeyStroke.getKeyStroke('S',InputEvent.CTRL_MASK));
      print.setAccelerator(KeyStroke.getKeyStroke('P',InputEvent.CTRL_MASK));
      exit.setAccelerator(KeyStroke.getKeyStroke('Q',InputEvent.CTRL_MASK));
      backout.setAccelerator(KeyStroke.getKeyStroke('Z',InputEvent.CTRL_MASK));
      cut.setAccelerator(KeyStroke.getKeyStroke('X',InputEvent.CTRL_MASK));
      copy.setAccelerator(KeyStroke.getKeyStroke('C',InputEvent.CTRL_MASK));
      paste.setAccelerator(KeyStroke.getKeyStroke('V',InputEvent.CTRL_MASK));
      find.setAccelerator(KeyStroke.getKeyStroke('F',InputEvent.CTRL_MASK));
      jumpto.setAccelerator(KeyStroke.getKeyStroke('G',InputEvent.CTRL_MASK));
      allselect.setAccelerator(KeyStroke.getKeyStroke('A',InputEvent.CTRL_MASK));
      autoline.setAccelerator(KeyStroke.getKeyStroke('W',InputEvent.CTRL_MASK));
      font.setAccelerator(KeyStroke.getKeyStroke('F',InputEvent.ALT_MASK));
      
      //ŽŽœš²éÕÒœçÃæ
      search= new SearchFrame(this);
       textArea.addCaretListener(new CaretListener(){
           public  void  caretUpdate(CaretEvent   e)
           {
               try{
                     int pos=textArea.getCaretPosition();
                      //»ñÈ¡ÐÐÊý
                     int lineOfC=textArea.getLineOfOffset(pos)+1;
                      //»ñÈ¡ÁÐÊý
                     int col=pos-textArea.getLineStartOffset(lineOfC   1)    1;
                     statuslabel.setText("µ±Ç°¹â±êλÖÃ:µÚ"+lineOfC+"ÐР,µÚ"+col+"ÁР ");
                 }
                 catch(Exception  ex){
                    statuslabel.setText("ÎÞ·š»ñµÃµ±Ç°¹â±êλÖà ");
                 }
           }
       });
    }

    
    private voidsizeWindowOnScreen(Notepad notepad, double widthRate,
         double heightRate) {
      Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
      notepad.setSize(new Dimension((int)(screenSize.width * widthRate),
            (int) (screenSize.height * heightRate)));
    }

    publicstatic void main(String[] args) {
      Notepad myNotepad = new Notepad();
    }
   @Override
    public voidactionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub
      if(e.getSource()==create){
         if (!(textArea.getText().equals(""))) {
            Object[] options = { "È·¶š", "È¡Ïû" };
            int response = JOptionPane
                  .showOptionDialog(null, "ÄãÊÇ·ñ±£Žæ","Ìá  ÊŸ",
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE, null,options,
                        options[0]);
            if(response == 0) {
               try {
                  FileDialog d = new FileDialog(this,"±£ŽæÎÄŒþ",
                        FileDialog.SAVE);
                  d.setVisible(true);
                  filename = d.getDirectory() + d.getFile();
                  if(filename.equals("nullnull")){
                     return;
                  }
                  else{
                     FileOutputStream fout = newFileOutputStream(filename
                           + ".txt");
                     byte bb[] = textArea.getText().getBytes();
                     fout.write(bb);
                     fout.close();
                     JOptionPane.showMessageDialog(null,"ÎÄŒþÒѱ£Žæ");
                     textArea.setText("");
                  }
               } catch (IOException ioe) {
                  System.err.println(e);
               }
            }
            if (response == 1){
               textArea.setText("");
               this.setTitle("ÐÂœšÎıŸÎĵµ");
               filename="";
               filepath="";
            }
         }
         else{
            this.setTitle("ÐÂœšÎıŸÎĵµ");
         }
      }
      if(e.getSource()==open){
         FileDialog fd1 = new FileDialog(this,"Žò¿ªÎÄŒþ",FileDialog.LOAD);
         fd1.setFile("*.txt");
         fd1.setVisible(true);

         filename = fd1.getFile();
         filepath = fd1.getDirectory();
         if(filepath!=null&&filename!=null){
            this.setTitle(filename);
            try {
               FileReader fr = new FileReader(filepath +filename);
               BufferedReader br = new BufferedReader(fr);
               String sinput = "";
               textArea.setText("");
               int lineNum = 0;
               while ((sinput = br.readLine()) != null) {
                  textArea.append(sinput + "\r\n");
                  lineNum++;
               }
            } catch (Exception ex) {
               ex.printStackTrace();
            }
         }
      }
      if(e.getSource()==save){
         try {
            if(filename.equals("")) {
               filename =JOptionPane.showInputDialog("ÇëÊäÈëÎÄŒþÃû", "java");
               FileOutputStream fout = newFileOutputStream(filename+".txt");
               byte bb[] = textArea.getText().getBytes();
               fout.write(bb);
               fout.close();
               JOptionPane.showMessageDialog(null,"Òѱ£Žæ");
            }else {
               FileOutputStream fout = newFileOutputStream(filepath+"\"+filename);
               byte bb[] = textArea.getText().getBytes();
               fout.write(bb);
               fout.close();
               flag=false;
               JOptionPane.showMessageDialog(null,"Òѱ£Žæ");
            }
         } catch (IOException ioe) {
            System.err.println(e);
         }
      }
      if(e.getSource()==saveas){
         save_asMethod();
      }
      if(e.getSource()==pageset){
         JOptionPane.showMessageDialog(this,"ÔÚŽòÓ¡µÄʱºòÓõœ£¡","Ÿ¯žæ¶Ô»°¿ò",JOptionPane.WARNING_MESSAGE);
      }
      if(e.getSource()==print){
         try{
            printjob=this.getToolkit().getPrintJob(this,"OK", null);
            graphics=printjob.getGraphics();//»ñµÃÒ»žöÓÃÓÚŽòÓ¡µÄGraphics¶ÔÏó
            graphics.translate(200, 300);
            textArea.printAll(graphics);//ŽòÓ¡
            printjob.end();//ÊÍ·Å
         }
         catch(Exception ex){
            JOptionPane.showMessageDialog(this,ex.getMessage());
         }
      }
      if(e.getSource()==exit){
         filename = Notepad.this.getTitle();
         if (flag == true) {
            int returnValue =JOptionPane.showConfirmDialog(null,
                  Notepad.this.getTitle() +"ÎÄŒþ»¹Ã»Óб£Žæ£¡ÐèÒª±£Žæ£¿", "ŒÇʱŸ",
                  JOptionPane.YES_NO_CANCEL_OPTION);
            if (returnValue == JOptionPane.YES_OPTION){
               save_asMethod();
            } else if (returnValue == JOptionPane.NO_OPTION){
               System.exit(0);

            } else{               
               setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            }
         }
         else{
            System.exit(0);
         }
      }
      if(e.getSource()==backout){
         JOptionPane.showMessageDialog(this,"ÄÜÁŠÓÐÏÞ£¬ÔÝΎʵÏÖ£¡","ÌáÊŸ",JOptionPane.WARNING_MESSAGE);
      }
      if(e.getSource()==cut||e.getSource()==cut_r){
         textArea.cut();
      }
      if(e.getSource()==copy||e.getSource()==copy_r){
         textArea.copy();
      }
      if(e.getSource()==paste||e.getSource()==paste_r){
         textArea.paste();
      }
      if(e.getSource()==delete||e.getSource()==delete_r){
         int start=textArea.getSelectionStart();
         int end=textArea.getSelectionEnd();
         textArea.replaceRange("", start, end);
      }
      if(e.getSource()==allselect||e.getSource()==allselect_r){
         textArea.selectAll();
      }
      if(e.getSource()==find){         
         search.setVisible(true);
      }
      if(e.getSource()==findnext){
         search.setVisible(true);
      }
      if(e.getSource()==jumpto){
         search.setVisible(true);
      }
      if(e.getSource()==datetime){
         nowdate=new Date();
         sdf= new SimpleDateFormat("'±ŸµØʱŒä:'yyyyÄêMMÔÂddÈÕ E  HHʱmm·Ö ");
         textArea.append(sdf.format(nowdate));
      }
      if(e.getSource()==autoline){
         if (a == 0) {
            textArea.setLineWrap(true);
            autoline.setText("¡Ì×Ô¶¯»»ÐÐ");
            a = 1;
         } else if (a == 1) {
            textArea.setLineWrap(false);
            autoline.setText("×Ô¶¯»»ÐÐ");
            a = 0;
         }
      }
      if(e.getSource()==metalstyle){
         changeLookFeel("javax.swing.plaf.metal.MetalLookAndFeel");
      }
      if(e.getSource()==motifstyle){
         changeLookFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
      }
      if(e.getSource()==windowsstyle){
         changeLookFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
      }
      if(e.getSource()==statusbar){
         if (a == 1) {
            statuslabel.setVisible(false);
            a = 0;
         } else if (a == 0) {
            this.add(statuslabel, BorderLayout.SOUTH);
            statuslabel.setVisible(true);
            statuslabel.setText("µ±Ç°×ÖÊý: "
                  +String.valueOf(textArea.getText().trim().length())
                  + " " + "µ±Ç°ÐÐÊý: "
                  + String.valueOf(textArea.getLineCount()));
            a = 1;
         }
      }
      if(e.getSource()==checkhelp){
         
      }
      if(e.getSource()==about){
         //showAbout();
         aboutNotepad.setVisible(true);
      }
    }
    public voidsave_asMethod() {
      FileDialog fd = new FileDialog(Notepad.this,"ÁíŽæΪ¡­",FileDialog.SAVE);
      fd.setFile("*.txt");
      fd.setVisible(true);
      filepath = fd.getDirectory();
      filename = fd.getFile();
      try {
         FileWriter fw = new FileWriter(filepath +filename);
         BufferedWriter bw = new BufferedWriter(fw);
         PrintWriter pw = new PrintWriter(bw);
         pw.println(textArea.getText());
         pw.flush();
         pw.close();
      } catch (Exception ex) {
         ex.printStackTrace();
      }
    }
    classMyTextArea extends JTextArea implements DropTargetListener {
      private static final long serialVersionUID =1L;
      public MyTextArea() {
         new DropTarget(this,DnDConstants.ACTION_COPY_OR_MOVE, this);
      }
      public void dragEnter(DropTargetDragEvent dtde){
      }
      public void dragOver(DropTargetDragEvent dtde){
      }
      public void dropActionChanged(DropTargetDragEventdtde) {
      }
      public void dragExit(DropTargetEvent dte) {
      }
      public void drop(DropTargetDropEvent event){
         // œÓÊÜžŽÖƲÙ×÷
         event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
         // »ñÈ¡ÍϷŵÄÄÚÈÝ
         Transferable transferable =event.getTransferable();
         DataFlavor[] flavors =transferable.getTransferDataFlavors();
         // ±éÀúÍÏ·ÅÄÚÈÝÀïµÄËùÓÐÊýŸÝžñÊœ
         for (int i = 0; i <flavors.length; i++) {
            DataFlavor d = flavors[i];
            try {
               //Èç¹ûÍÏ·ÅÄÚÈݵÄÊýŸÝžñÊœÊÇÎÄŒþÁбí
               if(d.equals(DataFlavor.javaFileListFlavor)){
                  //È¡³öÍϷŲÙ×÷ÀïµÄÎÄŒþÁбí
                  List<File> filelist= (List<File>)transferable.getTransferData(d);
                  for (Object f:filelist) {
                     filepath = ((File) f).getParent();
                     filename = ((File) f).getName();
                     if(filename.endsWith(".txt")||filename.endsWith(".java")||
                           filename.endsWith(".html")||filename.endsWith(".htm")||
                           filename.endsWith(".xml")||filename.endsWith(".bat")||
                           filename.endsWith(".js")||filename.endsWith(".aspx")||
                           filename.endsWith(".jsp")||filename.endsWith(".ini")){
                        FileReader fr = newFileReader(filepath+"\"+filename);
                        BufferedReader br = new BufferedReader(fr);
                        String sinput = "";
                        textArea.setText("");
                        setTitle(filename);
                        while ((sinput = br.readLine()) != null) {
                           textArea.append(sinput + "\r\n");
                        }
                     }
                     else{
                        JOptionPane.showMessageDialog(this,"²»Ö§³ÖÕâÖÖÀàÐ͵ÄÎÄŒþ£¡");
                     }
                  }
               }
            } catch (Exception e) {
               e.printStackTrace();
            }
            // Ç¿ÖÆÍϷŲÙ×÷œáÊø£¬Í£Ö¹×èÈûÍÏ·ÅÔŽ
            event.dropComplete(true);
         }
      }
    }
   //»ñµÃŒôÇаåÖеÄÎıŸÄÚÈÝ
    publicstatic String getSysClipboardText() {
      String ret = "";
      Clipboard sysClip =Toolkit.getDefaultToolkit().getSystemClipboard();
      // »ñÈ¡ŒôÇаåÖеÄÄÚÈÝ
      Transferable clipTf =sysClip.getContents(null);
      if (clipTf != null) {
         // Œì²éÄÚÈÝÊÇ·ñÊÇÎıŸÀàÐÍ
         if(clipTf.isDataFlavorSupported(DataFlavor.stringFlavor)){
            try {
               ret = (String) clipTf
                     .getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
               e.printStackTrace();
            }
         }
      }
      return ret;
    }
    
    classSearchFrame extends JFrame implements ActionListener, ItemListener{
      JLabel label1, label2, label3;
      JButton next, replace, jump, cancel;
      JTextField findtext, replacetext;
      JRadioButton rb1, rb2;
      ButtonGroup group;
      JCheckBox box;
      Notepad notepad = null;
      String sub1 = "", sub2 = "";
      int n = -1;
      boolean isup = false;//ÅжÏÊÇ·ñÊÇ×îºóÒ»žöÕÒµœµÄÄÚÈÝʱÓõœ
      boolean direction = true;// ÅжϲéÕÒ·œÏò ÏòÏÂΪtrue

      SearchFrame(Notepad n) {
         notepad = n;
         label1 = new JLabel("²éÕÒÄÚÈÝ(N):");
         label2 = new JLabel("·œÏò");
         label3 = new JLabel("Ì滻Ϊ(P)");

         next = new JButton("²éÕÒÏÂÒ»žö(F)");
         cancel = newJButton("      È¡      Ïû     ");
         replace = newJButton("      Ìæ      »»     ");
         jump = newJButton("      ×ª      µœ     ");
         findtext = new JTextField(15);
         replacetext = new JTextField(15);

         rb1 = new JRadioButton("ÏòÏÂ(U)", true);
         rb2 = new JRadioButton("ÏòÉÏ(D)");

         group = new ButtonGroup();
         // ŽŽœš×éŒþ
         box = new JCheckBox("Çø·ÖŽóСЎ(C)");
         Container con = getContentPane();
         con.setLayout(null);// ÉèÖòŒŸÖΪ¿Õ
         group.add(rb1);
         group.add(rb2);// œ«µ¥Ñ¡°ŽÅ¥ŒÓµœ°ŽÅ¥×éÖÐ

         con.add(label1);// ²éÕÒ
         label1.setBounds(10, 10, 85, 25);

         con.add(label3);// Ì滻Ϊ
         label3.setBounds(10, 45, 85, 25);

         con.add(findtext);// ÎıŸ
         findtext.setBounds(90, 10, 180, 25);

         con.add(replacetext);// ÎıŸ
         replacetext.setBounds(90, 45, 180, 25);

         con.add(next);// ²éÕÒÏÂÒ»žö
         next.setBounds(280, 10, 120, 25);

         con.add(label2);// ·œÏò
         label2.setBounds(135, 80, 50, 25);

         con.add(box);
         box.setBounds(10, 115, 120, 25);

         con.add(rb1);// ÏòÏÂ
         rb1.setBounds(130, 115, 70, 25);

         con.add(rb2);// ÏòÉÏ
         rb2.setBounds(200, 115, 70, 25);

         con.add(cancel);// È¡Ïû
         cancel.setBounds(280, 115, 120, 25);

         con.add(replace);// Ìæ»»
         replace.setBounds(280, 45, 120, 25);

         con.add(jump);// תµœ
         jump.setBounds(280, 80, 120, 25);

         next.addActionListener(this);
         cancel.addActionListener(this);
         replace.addActionListener(this);
         jump.addActionListener(this);
         box.addItemListener(this);
         findtext.addActionListener(this);
         replacetext.addActionListener(this);
         rb1.addItemListener(this);
         rb2.addItemListener(this);
         // ×¢²áŒàÌý

         setBounds(500, 300, 420, 180);
         setVisible(false);
         setResizable(false);
         setTitle("²éÕÒ");
         validate();
      }

      @Override
      public void actionPerformed(ActionEvent e){
         // TODO Auto-generated method stub
         sub1 = notepad.textArea.getText();
         sub2 = findtext.getText();
         if(!isup){//Èç¹û²»Çø·ÖŽóСЎ£šÄ¬Èϲ»Çø·ÖŽóСЎ£©
            sub1 = sub1.toLowerCase();//œ«sub1ת»»³ÉСЎ
            sub2 = sub2.toLowerCase();//œ«sub2ת»»³ÉСЎ
         }
         if(!direction){
            n = sub1.lastIndexOf(sub2);//ÔÚÎıŸÇøÖвéÕÒÎıŸ¿òÖеÄÄÚÈÝ
         }else {
            n = sub1.indexOf(sub2);//ÔÚÎıŸÇøÖвéÕÒÎıŸ¿òÖеÄÄÚÈÝ
         }
         //²éÕÒÏÂÒ»žö
         if (e.getSource() == next || e.getSource() ==findtext){
            if(n != -1){
               notepad.toFront();//Èç¹ûŽËŽ°¿ÚÊÇ¿ÉŒûµÄ£¬Ôòœ«ŽËŽ°¿ÚÖÃÓÚÇ°¶Ë£¬²¢¿ÉÒÔœ«ÆäÉèΪœ¹µãWindow
               notepad.textArea.select(n, n + sub2.length());//Ñ¡ÖвéÕÒµÄÄÚÈÝ
            }else{
               JOptionPane.showMessageDialog(this,"ÄúÊäÈëµÄÄÚÈÝûÓÐÕÒµœ£¡","ÌáÊŸ",JOptionPane.WARNING_MESSAGE);
            }
         }
         //È¡Ïû
         if (e.getSource() == cancel){
            this.setVisible(false);
         }
         //תµœ
         if (e.getSource() == jump){
            int i = 0, j = 1;
            char ch[];
            try{
               int raw = Integer.parseInt(findtext.getText());//µÃµœÎıŸ¿òÖеÄÎıŸ
               String s = notepad.textArea.getText();
               ch = new char[s.length()];
               s.getChars(0, s.length() - 1, ch, 0);
               while (j < raw) {
                  i++;
                  if (ch[i] == '\n') {
                     j++;
                  }
                  if (i == s.length())
                     break;
               }
               // תµœµÚÒ»ÐÐ
               if (raw == 1) {
                  notepad.textArea.setCaretPosition(0);
               } else {
                  notepad.textArea.setCaretPosition(i + 1);//תµœÖž¶šÐÐ
               }
            } catch (Exception a) {
               JOptionPane.showMessageDialog(this,"ÄãÊäÈëµÄλÖò»¶ÔÎÞ·šµœŽï£¡", "ÌáÊŸ",
                     JOptionPane.WARNING_MESSAGE);
            }
         }
         //Ìæ»»
         if (e.getSource() == replace)
         {
            if (n != -1) {
               String sub3 = replacetext.getText();
               notepad.textArea.select(n, n +sub2.length());//Ñ¡ÖвéÕÒµÄÄÚÈÝ
               notepad.textArea.replaceRange(sub3, n, n +sub2.length());//Ì滻ѡÖÐλÖõÄÎıŸ

               sub1 =notepad.textArea.getText();//µÃµœÎıŸÇøÖеÄÎıŸ
               sub2 = findtext.getText();//µÃµœÎıŸ¿òÖеÄÎıŸ
               if(!isup)//Èç¹û²»Çø·ÖŽóСЎ£šÄ¬Èϲ»Çø·ÖŽóСЎ£©
               {
                  sub1 =sub1.toLowerCase();//œ«sub1ת»»³ÉСЎ
                  sub2 =sub2.toLowerCase();//œ«sub2ת»»³ÉСЎ
               }
               if (!direction)
                  n =sub1.lastIndexOf(sub2);//ÔÚÎıŸÇøÖвéÕÒ×îºó³öÏÖµÄÎıŸ¿òÖеÄÄÚÈÝ
               else
                  n =sub1.indexOf(sub2);//ÔÚÎıŸÇøÖвéÕÒ×îÏȳöÏÖµÄÎıŸ¿òÖеÄÄÚÈÝ
               notepad.toFront();//Èç¹ûŽËŽ°¿ÚÊÇ¿ÉŒûµÄ£¬Ôòœ«ŽËŽ°¿ÚÖÃÓÚÇ°¶Ë£¬²¢¿ÉÒÔœ«ÆäÉèΪœ¹µãWindow
               if (n != -1) {
                  notepad.textArea.select(n, n +sub2.length());//Ñ¡ÖвéÕÒÄÚÈÝ
               } else
                  JOptionPane.showMessageDialog(this,"ËùÖž¶šµÄÎıŸÃ»ÓÐÕÒµœ£¡",
                        "ŒÇʱŸ", JOptionPane.WARNING_MESSAGE);
            } else {
               JOptionPane.showMessageDialog(this,"ËùÖž¶šµÄÎıŸÃ»ÓÐÕÒµœÎÞ·šÌæ»»£¡",
                     "ŒÇʱŸ", JOptionPane.WARNING_MESSAGE);
            }
         }
      }

      @Override
      public void itemStateChanged(ItemEvent ee){
         // TODO Auto-generated method stub
         if (ee.getSource() == next) {
            if (next.isSelected()) {
               isup = true;
            } else
               isup = false;
         }
         if (ee.getSource() == rb1) {
            if (rb1.isSelected()) {
               direction = true;
            }
         }
         if (ee.getSource() == rb2) {
            if (rb2.isSelected()) {
               direction = false;
            }
         }
      }
    }
    classAboutNotepadDialog extends JDialog{
      public AboutNotepadDialog() {
         // TODO Auto-generated constructor stub
         this.setTitle("¹ØÓÚŒÇʱŸ");
         JEditorPane jEditorPane = newJEditorPane();
         jEditorPane.setEditable(false);
         jEditorPane.setContentType("text/html");
         jEditorPane.setText("<html><bodyalign=left><br>"+
               "<font>Ãû³Æ:С»šŒÇʱŸ<br>"+
               "°æ±Ÿ:Version1.0<br>"+
               "×÷Õß:»šÐ²ý<br>"+
               "ÓÊÏä:<ahref=mailto:592409652@qq.commce_href=mailto:592409652@qq.com?>592409652@qq.com</a><br>"+
               "²©¿Í:<ahref=http://hi.baidu.com/huaxinchang/home>http://hi.baidu.com/huaxinchang/home</a><br>"+
               "°æÈš:žÃ³ÌÐòΪ×ÔÓÉÈíŒþ¿ÉÈÎÒâÒýÓûòÐÞžÄ<br></body></html>");
         jEditorPane.addHyperlinkListener(newHyperlinkListener(){
            public void hyperlinkUpdate(HyperlinkEvente){
               if (e.getEventType() ==HyperlinkEvent.EventType.ACTIVATED){
                  try{
                     String command = "explorer.exe " +e.getURL().toString();
                     Runtime.getRuntime().exec(command);
                  }
                  catch (Exception ex){
                  ex.printStackTrace();
                  System.err.println("connection error");
                  }
               }
            }
         });
         this.getContentPane().add(jEditorPane);
         this.setAlwaysOnTop(true);
          this.setSize(300,200);
         this.setLocationRelativeTo(Notepad.this);
         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
         this.setResizable(false);
      }
      private static final long serialVersionUID =1L;      
    }
    
    private voidshowAbout() {
      if (this.aboutDialog == null) {
         String[] arrStrLabel = new String[] {
               "ÈíŒþ£º" + softwarename,
               "°æ±Ÿ£º" + version,
               "×÷Õߣº" + author,
               "<html>²©¿Í:<a href='" + blog + "'>" + blog+"</a></html>",
               "°æÈš£ºŽËΪ×ÔÓÉÈíŒþ¿ÉÒÔÈÎÒâÒýÓûòÐÞžÄ" };
         this.aboutDialog = new AboutDialog(this, true,arrStrLabel);
         this.aboutDialog.addLinkByIndex(3, blog);
         this.aboutDialog.setVisible(true);
      } else {
         this.aboutDialog.setLocationRelativeTo(this);
         this.aboutDialog.setVisible(true);
      }
    }
    
    classBaseDialog extends JDialog implements BaseAction {
      private static final long serialVersionUID =1L;

      public BaseDialog(JFrame owner, boolean modal){
         super(owner, modal);
      }

      public void onEnter() {
      }

      public void onCancel() {
      }
    }
    
    interfaceBaseAction {
      public void onEnter(); //¡°È·¶š¡±²Ù×÷µÄœÓ¿Ú·œ·š
      public void onCancel(); //¡°È¡Ïû¡±²Ù×÷µÄœÓ¿Ú·œ·š
    }
    
    classAboutDialog extends BaseDialog implements ActionListener {
      private static final long serialVersionUID =1L;
      private int lines = 1; //ÏÔÊŸ±êÇ©µÄÐÐÊý
      private GridLayout layout = null;
      private JPanel pnlMain = (JPanel)this.getContentPane();
      private JPanel pnlCenter = new JPanel();
      private JPanel pnlEast = new JPanel();
      private JPanel pnlWest = new JPanel();
      private JPanel pnlSouth = new JPanel();
      private JPanel pnlNorth = new JPanel();
      private JLabel lblWest = new JLabel(" ");
      private JLabel lblNorth = new JLabel(" ");
      private JLabel lblEast = new JLabel(" ");
      private JButton btnOk = newJButton("È·¶š");
      privateLinkedList<JLabel> labelList = newLinkedList<JLabel>();//Žæ·ÅÏÔÊŸ±êÇ©µÄÁŽ±í

      public AboutDialog(JFrame owner) {
         this(owner, true, 1);
      }

      public AboutDialog(JFrame owner, boolean modal){
         this(owner, modal, 1);
      }

      public AboutDialog(JFrame owner, boolean modal,int lines) {
         super(owner, modal);
         this.checkLines(lines);
         this.init();
         this.addListeners();
         this.setSize(300, 200);
         this.setLocationRelativeTo(owner);
         this.setResizable(false);
         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      }

      public AboutDialog(JFrame owner, boolean modal,String[] arrStrLabel) {
         this(owner, modal, arrStrLabel.length);
         if (arrStrLabel.length > 0){
            for (int i = 0; i < this.lines;i++) {
               this.labelList.get(i).setText(arrStrLabel[i]);
            }
         }
      }
      
      private void init() {
         this.setTitle("¹ØÓÚ");
         this.pnlWest.add(this.lblWest);
         this.pnlNorth.add(this.lblNorth);
         this.pnlEast.add(this.lblEast);
         this.pnlSouth.add(this.btnOk);
         this.pnlMain.add(this.pnlWest,BorderLayout.WEST);
         this.pnlMain.add(this.pnlNorth,BorderLayout.NORTH);
         this.pnlMain.add(this.pnlEast,BorderLayout.EAST);
         this.pnlMain.add(this.pnlSouth,BorderLayout.SOUTH);
         this.layout = new GridLayout(this.lines,1);
         this.pnlCenter.setLayout(this.layout);
         this.initLabelList();
         this.pnlMain.add(this.pnlCenter,BorderLayout.CENTER);
      }

      
      private void initLabelList() {
         for (int i = 0; i < this.lines;i++) {
            this.appendLabelList();
         }
      }

      
      private boolean appendLabelList() {
         if (this.labelList.size() <this.lines) {
            JLabel lblTemp = new JLabel(" ");
            this.labelList.add(lblTemp);
            this.pnlCenter.add(lblTemp);
            return true;
         }
         return false;
      }

      
      private int checkLines(int lines) {
         if (lines <= 0) {
            this.lines = 1;
         } else {
            this.lines = lines;
         }
         return this.lines;
      }

      
      private int checkIndex(int index) {
         if (index < 0) {
            index = 0;
         } else if (index >=this.labelList.size()) {
            index = this.labelList.size() - 1;
         }
         return index;
      }

      
      private void addListeners() {
         this.btnOk.addActionListener(this);
      }

      
      public void addLinkByIndex(int index, finalString strLink) {
         if (index < 0 || index>= lines || strLink == null || strLink.isEmpty()){
            return;
         }
         JLabel lblTemp = this.labelList.get(index);
         lblTemp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
         lblTemp.addMouseListener(new MouseAdapter(){
            public void mouseClicked(MouseEvent e) {
               try {
                  //µ±ÓÃÊó±êµã»÷ŽË±êǩʱ£¬œ«µ÷ÓÃϵͳÃüÁŽò¿ªÍøÒ³
                  Runtime.getRuntime().exec("cmd /c start " +strLink);
               } catch (Exception x) {
                  // Èç¹û²Ù×÷ϵͳ²»Ö§³ÖŽËÃüÁœ«Å׳öÒì³£
                  x.printStackTrace();
               }
            }
         });
      }

      
      public void setStringByIndex(int index, StringstrLabel) {
         this.labelList.get(this.checkIndex(index)).setText(strLabel);
      }

      
      public String getStringByIndex(int index) {
         returnthis.labelList.get(this.checkIndex(index)).getText();
      }

      
      public void actionPerformed(ActionEvent e){
         if (this.btnOk.equals(e.getSource())) {
            this.onCancel();
         }
      }

      
      public void onEnter() {
      }

      
      public void onCancel() {
         this.dispose();
      }
    }
    //žüзçžñÍâ¹Û·œ·š
    voidchangeLookFeel(String className) {
      try {
         UIManager.setLookAndFeel(className);
      } catch (Exception e) {
         System.out.println(e);
      }
      SwingUtilities.updateComponentTreeUI(this);
    }
}
原创粉丝点击