• 大小: 73KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-06-02
  • 语言: Java
  • 标签: 记事本  

资源简介

记事本的基本编辑功能以及自定义工具栏,字体功能,帮助文档等

资源截图

代码片段和文件信息

/*
 * To change this license header choose License Headers in Project Properties.
 * To change this template file choose Tools | Templates
 * and open the template in the editor.
 */

package note;
import java.util.Calendar.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.awt.*;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.event.ListSelectionListener;


/**
 *
 * @author LHM
 */
public class MyNote extends javax.swing.Jframe {

    /**
     * Creates new form MyNote
     */
    JFileChooser fileDialog = new JFileChooser();
    BufferedReader in;
    FileReader fileReader;
    BufferedWriter out;
    FileWriter fileWriter;
    File dir;
    String name;

    public void save(){
        int state=fileDialog.showSaveDialog(this);
        if(state==JFileChooser.APPROVE_OPTION){
            try{
                dir=fileDialog.getCurrentDirectory();
                name=fileDialog.getSelectedFile().getName();
                File file=new File(dirname);
                fileWriter=new FileWriter(file);
                out=new BufferedWriter(fileWriter);
                out.write(jTextArea1.getText());
                out.close();
                fileWriter.close();
            }
            catch(IOException exp){}
            
         }
    }
    public MyNote() {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd“);
        String createdate = sdf.format(date);
        initComponents();
        this.jTextArea1.setComponentPopupMenu(jPopupMenu1);
        jLabel6.setText(createdate);
        setDefaultCloseOperation(Jframe.DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter(){
            public void windowClosing(WindowEvent e)
                {
                    if(jTextArea1.getText().length()!=0){
                        int n = JOptionPane.showConfirmDialog(null “文件是否已保存,确认是否保存“ “提示“ JOptionPane.YES_NO_OPTION);
                        if (n == JOptionPane.YES_OPTION) {
                            save();
                        } else if (n == JOptionPane.NO_OPTION) {
                            System.exit(0);
                        }
                    }
                else{
                    int flag = JOptionPane.showConfirmDialog(null “确定关闭吗?““提示“JOptionPane.YES_NO_OPTIONJOptionPane.INFORMATION_MESSAGE);
                    if(JOptionPane.YES_OPTION == flag)
                        System.exit(0);
                    else
                        return;                        
                    }

                }
        });  
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify thi

评论

共有 条评论