⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmnote.java~102~

📁 此程序是用Java实现的一个图书管理系统,再加以可以做毕业设计用而,而且实现的工能相对效全.
💻 JAVA~102~
📖 第 1 页 / 共 2 页
字号:
package bookmanager;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import javax.swing.JTextArea;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import com.borland.dbswing.FontChooser;
import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.util.Calendar;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.sql.Date;
import java.sql.Time;

public class frmnote extends JFrame{//这个界面实现记事本的功能
    JPanel contentPane;
    JMenuBar MenuBar = new JMenuBar();
    JMenu Menu = new JMenu();
    JMenuItem tem = new JMenuItem();
    JMenuItem tare = new JMenuItem();
    JMenuItem menuper = new JMenuItem();
    JMenuItem menubich = new JMenuItem();
    JMenuItem good = new JMenuItem();
    JMenuItem exitmenu = new JMenuItem();
    JMenu second = new JMenu();
    JMenuItem hill = new JMenuItem();
    JMenuItem copy = new JMenuItem();
    JMenuItem poot = new JMenuItem();
    JMenuItem delet = new JMenuItem();
    JMenuItem poue = new JMenuItem();
    JMenuItem datetime = new JMenuItem();
    JMenu reet = new JMenu();
    JMenuItem write = new JMenuItem();
    JMenu treeth = new JMenu();
    JMenuItem help = new JMenuItem();
    JMenuItem helpbook = new JMenuItem();
    private JTextArea txanote = new JTextArea();
    BorderLayout borderLayout1 = new BorderLayout();
    JFileChooser opendialog = new JFileChooser();
    FontChooser font = new FontChooser();
    JCheckBoxMenuItem jCheckBoxMenuItem1 = new JCheckBoxMenuItem();
     Calendar date;
     String strtext="";
     boolean dirty=false;
    JPopupMenu jPopupMenu1 = new JPopupMenu();
    JMenuItem jMenuItem1 = new JMenuItem();
    JMenuItem jMenuItem2 = new JMenuItem();
    JMenuItem jMenuItem3 = new JMenuItem();
    JMenuItem jMenuItem4 = new JMenuItem();
    JMenuItem jMenuItem5 = new JMenuItem();
    public frmnote() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    private void jbInit() throws Exception {
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(borderLayout1);
        this.setJMenuBar(MenuBar);
        setSize(new Dimension(400, 300));
        setTitle("记事本");
        contentPane.setBorder(null);
        Menu.setText("文件(F_)");
        tem.setText("新建(N_)        Ctrl+N     ");
        tem.addActionListener(new frmnote_tem_actionAdapter(this));
        tare.setText("打开(O_)...     Ctrl+O");
        tare.addActionListener(new frmnote_tare_actionAdapter(this));
        menuper.setText("保存(S_)        Ctrl+S");
        menuper.addActionListener(new frmnote_menuper_actionAdapter(this));
        menubich.setText("另存为(A_)...");
        menubich.addActionListener(new frmnote_menubich_actionAdapter(this));
        good.setText("页面颜色设置(U_)");
        good.addActionListener(new frmnote_good_actionAdapter(this));
        exitmenu.setText("退出(X_)");
        exitmenu.addActionListener(new frmnote_exitmenu_actionAdapter(this));
        second.setText("编辑(E_)");
        copy.setText("复制(C_)    Ctrl+C");
        copy.addActionListener(new frmnote_copy_actionAdapter(this));
        hill.setText("剪切(T_)    Ctrl+X");
        hill.addActionListener(new frmnote_hill_actionAdapter(this));
        poot.setText("粘贴(P_)    Ctrl+V");
        poot.addActionListener(new frmnote_poot_actionAdapter(this));
        delet.setText("删除(L_)    DEL");
        delet.addActionListener(new frmnote_delet_actionAdapter(this));
        poue.setText("全选(A_)    Ctrl+A");
        poue.addActionListener(new frmnote_poue_actionAdapter(this));
        datetime.setText("日期/时间(D_) F5");
        datetime.addActionListener(new frmnote_datetime_actionAdapter(this));
        reet.setText("格式(O_)");
        write.setText("字体(F_)...");
        write.addActionListener(new frmnote_write_actionAdapter(this));
        treeth.setText("帮助(H_)");
        help.setText("帮助主题(H_)");
        help.addActionListener(new frmnote_help_actionAdapter(this));
        helpbook.setText("关于记事本(A_)");
        txanote.setBorder(null);
        txanote.setText("");
        txanote.addMouseListener(new frmnote_txanote_mouseAdapter(this));
        txanote.addCaretListener(new frmnote_txanote_caretAdapter(this));
        txanote.addAncestorListener(new frmnote_txanote_ancestorAdapter(this));
        helpbook.addActionListener(new frmnote_helpbook_actionAdapter(this));
        jCheckBoxMenuItem1.setText("自动换行(W_)");
        jCheckBoxMenuItem1.addAncestorListener(new
                frmnote_jCheckBoxMenuItem1_ancestorAdapter(this));
        jCheckBoxMenuItem1.addItemListener(new
                frmnote_jCheckBoxMenuItem1_itemAdapter(this));
        jMenuItem1.setText("复制");
        jMenuItem1.addActionListener(new frmnote_jMenuItem1_actionAdapter(this));
        jMenuItem2.setText("粘贴");
        jMenuItem2.addActionListener(new frmnote_jMenuItem2_actionAdapter(this));
        jMenuItem3.setText("剪切");
        jMenuItem3.addActionListener(new frmnote_jMenuItem3_actionAdapter(this));
        jMenuItem4.setText("删除");
        jMenuItem4.addActionListener(new frmnote_jMenuItem4_actionAdapter(this));
        jMenuItem5.setText("全选");
        jMenuItem5.addActionListener(new frmnote_jMenuItem5_actionAdapter(this));
        MenuBar.add(Menu);
        MenuBar.add(second);
        MenuBar.add(reet);
        MenuBar.add(treeth);
        Menu.add(tem);
        Menu.add(tare);
        Menu.add(menuper);
        Menu.add(menubich);
        Menu.addSeparator();
        Menu.add(good);
        Menu.addSeparator();
        Menu.add(exitmenu);
        second.add(poot);
        second.add(hill);
        second.add(copy);
        second.add(delet);
        second.addSeparator();
        second.add(poue);
        second.add(datetime);
        reet.add(jCheckBoxMenuItem1);
        reet.add(write);
        treeth.add(help);
        treeth.addSeparator();
        treeth.add(helpbook);
        contentPane.add(txanote, java.awt.BorderLayout.CENTER);
        jPopupMenu1.add(jMenuItem1);
        jPopupMenu1.add(jMenuItem2);
        jPopupMenu1.add(jMenuItem3);
        jPopupMenu1.add(jMenuItem4);
        jPopupMenu1.add(jMenuItem5);
    }
    private void paste()
    {
        if(this.strtext.length()>0)
        {
            txanote.insert(this.strtext,txanote.getCaretPosition());
            this.dirty=true;
        }
    }
    private void copy()
    {
        try{
            String str = txanote.getSelectedText();
            if (str.length() != 0) {
                this.strtext = str;
            }
        }catch(Exception e){
            txanote.setText("复制出错");
        }
    }
    private void cut()
    {
        try{
            String str = txanote.getSelectedText();
            if (str.length() != 0) {
                this.strtext = str;
                txanote.replaceRange("",txanote.getSelectionStart(),txanote.getSelectionEnd());
                this.dirty=true;
            }
        }catch(Exception e){
            txanote.setText("剪切出错");
        }
    }
    private void delete()
    {
        txanote.replaceRange("",txanote.getSelectionStart(),txanote.getSelectionEnd());
        this.dirty=true;
    }
    public void help_actionPerformed(ActionEvent e) {
        int i=JOptionPane.showConfirmDialog(this,"找不到,是否亲自动手进行搜索!",
                                      "window帮助",JOptionPane.YES_NO_OPTION);
  if(i==1)
  {
      JOptionPane.showMessageDialog(this,"找不到,请重新安装系统软件!",
                                    "window帮助",JOptionPane.YES_OPTION);
  }
  else
  {
      opendialog.showOpenDialog(this);
            File file;
            BufferedReader on = null;
            file = new File(opendialog.getSelectedFile().getPath());
            String chars = null;
            try {
                on = new BufferedReader(new FileReader(file));
                chars = on.readLine();
            } catch (FileNotFoundException ex2) {
            } catch (IOException ex2) {
                txanote.setText(ex2.getClass().getName() + ":" + ex2.getMessage());
            } while (chars != null) {
                txanote.append(new String(chars) + "\r\n");
                try {
                    chars = on.readLine();
                } catch (IOException ex1) {
                }
            }
            if (on != null) {
                try {
                    on.close();
                } catch (IOException ex) {
                }
            }
            this.repaint();
  }
    }

    public void helpbook_actionPerformed(ActionEvent e) {
        dialognotebook dnb=new dialognotebook();
        dnb.setResizable(false);
        dnb.setSize(260,250);
        dnb.setLocation(100,100);
        dnb.show();
    }

    public void tem_actionPerformed(ActionEvent e) {
      if(txanote.getText().equals("")==false)
      {
          int i = JOptionPane.showConfirmDialog(this, "文件内容己经改变,想保存文件吗?",
                                                "记事本",
                                                JOptionPane.YES_NO_CANCEL_OPTION);
          if (i == 0) {
              opendialog.showSaveDialog(this);
              File file;
              BufferedWriter on = null;
             file = new File(opendialog.getSelectedFile().getPath());
                  String chars = null;
                  try {
                      on = new BufferedWriter(new FileWriter(file));
                      chars = txanote.getText();
                  } catch (FileNotFoundException ex2) {
                  } catch (IOException ex2) {
                  }
                  if (chars != null) {
                      try {
                          on.write(chars);
                          on.newLine();
                          chars = txanote.getText();
                      } catch (IOException ex1) {
                      }
                  }
                  if (on != null) {
                      try {
                          on.flush();
                          on.close();
                      } catch (IOException ex) {
                      }
                  }
                  this.repaint();
              } else if (i == 1) {
                  txanote.setText("");
                  return;
              } else
                  return;
          }
    }
    public void tare_actionPerformed(ActionEvent e){
        opendialog.showOpenDialog(this);
            File file;
            BufferedReader on = null;
            file = new File(opendialog.getSelectedFile().getPath());
            String chars = null;
            try {
                on = new BufferedReader(new FileReader(file));
                chars = on.readLine();
            } catch (FileNotFoundException ex2) {
            } catch (IOException ex2) {
                txanote.setText(ex2.getClass().getName() + ":" + ex2.getMessage());
            } while (chars != null) {
                txanote.append(new String(chars) + "\r\n");
                try {
                    chars = on.readLine();
                } catch (IOException ex1) {
                }
            }
            if (on != null) {
                try {
                    on.close();
                } catch (IOException ex) {
                }
            }
            this.repaint();
}
    public void menuper_actionPerformed(ActionEvent e) {
        opendialog.showSaveDialog(this);
        File file;
          String chars = null;
          BufferedWriter on = null;
          try {

            file = new File(opendialog.getSelectedFile().getPath());


                on = new BufferedWriter(new FileWriter(file));
                chars = txanote.getText();
            }
            catch (FileNotFoundException ex2) {
            }
            catch (IOException ex2) {
            } if (chars != null) {
                try {
                    on.write(chars);
                    on.newLine();
                    chars=txanote.getText();
                } catch (IOException ex1) {
                }
            }
            if (on != null) {
                try {
                    on.flush();
                    on.close();
                } catch (IOException ex) {
                }
            }
            this.repaint();
     }

    public void exitmenu_actionPerformed(ActionEvent e) {
        this.dispose();
    }

    public void write_actionPerformed(ActionEvent e) {
        font.setFrame(this);
        if(font.showDialog())
        {
            txanote.setFont(font.getSelectedFont());
        }
    }

    public void menubich_actionPerformed(ActionEvent e) {
        opendialog.showSaveDialog(this);
       File file;
           BufferedWriter on = null;
             String chars = null;
            try {
           file = new File(opendialog.getSelectedFile().getPath());


               on = new BufferedWriter(new FileWriter(file));
               chars = txanote.getText();
           } catch (FileNotFoundException ex2) {
           } catch (IOException ex2) {
           } if (chars != null) {
               try {
                   on.write(chars);
                   on.newLine();
                   chars=txanote.getText();
               } catch (IOException ex1) {
               }
           }
           if (on != null) {
               try {
                   on.flush();
                   on.close();
               } catch (IOException ex) {
               }
           }
           this.repaint();
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -