程序运行图片:
/**
* @author 廖俊瑶
*/
package editPlus;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
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.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.UIManager;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
@SuppressWarnings("serial")
public class EditPlus extends JFrame implements ActionListener {
// 定义变量
private JMenuBar jmb;// 菜单条
private JMenu jmfile, jmedit, jmhelp;// 菜单
private JMenuItem jmtabout, jmtfiles[], jmtedits[];// 菜单项
private JMenuItem popMenuItems[];
private JToolBar jtb;// 工具条
private JTextArea jta;// 文本域
private JPopupMenu popmenu;// 弹出式菜单
@SuppressWarnings("rawtypes")
private JComboBox jcbfont, jcbsize;// 组合框
private JColorChooser jcc;// 颜色选择框
private JButton fontcolor, clearall;// 按钮
private Color color;// 颜色
private Font menufont, font;// 字体
private JLabel jlfont, jlsize, jlstyle, jlcolor, jlstastic;// 标签
private JCheckBox jcbbold, jcbitalic;// 复选框
private JCheckBoxMenuItem jmtlinewrap;// 复选菜单项
private JPanel p1, p2, p3;
private Dimension dim;
private JFileChooser jfc;
private FileWriter fw;
private FileReader fr;
private String path, time;
private int stastic;
private boolean isSaved = false, isUpdated = false;
// 构造函数
@SuppressWarnings({ "unchecked", "rawtypes" })
public EditPlus() {
super("Edit++");// 设置窗口标题
menufont = new Font("微软雅黑", Font.PLAIN, 14);// UI字体
dim = this.getToolkit().getScreenSize();// 获取屏幕分辨率
jmb = new JMenuBar();
this.setUIFont();// 把各组件的字体设置为menufont
this.setSize(dim.width * 2 / 3, dim.height * 2 / 3);// 设置窗口大小
this.setJMenuBar(jmb);
// 创建菜单
jmfile = new JMenu("文件");
jmedit = new JMenu("编辑");
jmhelp = new JMenu("帮助");
// 创建菜单项
String[] jmfileStr = { "新建", "打开", "保存", "另存为", "退出" };
jmtfiles = new JMenuItem[jmfileStr.length];
for (int i = 0; i < jmfileStr.length; i++) {
jmtfiles[i] = new JMenuItem(jmfileStr[i]);
jmtfiles[i].addActionListener(this);
jmfile.add(jmtfiles[i]);
if (i == 3) {