Java编写的简单记事本
// 替换对话框组件 private JLabel s_findTargetLabel = null;// 查找内容标签 private JTextField s_targetTextField = null;// 输入查找目标的 input private JButton s_findButton = null;// 查找按钮 private JLabel replaceLabel = null;// 查找内容标签 private JTextField replaceTargetTextField = null;// 输入查找目标的 input private JButton replaceButton = null;// 查找按钮 private JLabel nothingLabel_first = null;// 占位标签 first private JLabel nothingLabel_second = null;// 占位标签 second private JButton replaceAllButton = null;// 替换全部 private JCheckBox s_ignoreCaseCheckBox = null;// 区分大小写 private JLabel nothingLabel_third = null;// 占位标签 third private JButton s_cancleFindButton = null;// 取消按钮 private boolean isSearchFind = false;// 是否为"替换"对话框中的"查找下一个"按钮 private boolean isReplaceOne = false;// 是否替换一个 private boolean isRepalceAll = false;// 是否替换全部 private int time = 0;
Java 编写的简单记事本
目录结构:
下面是 NotepadGUI.java 中的代码
import java.awt.BorderLayout; import ponent; import java.awt.Dimension; import java.awt.Event; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GraphicsEnvironment; import java.awt.GridLayout; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Stack; import java.util.regex.Matcher; import java.util.regex.Pattern;
public class NotepadGUI implements ActionListener, MouseMotionListener,
PopupMenuListener, CaretListener, UndoableEditListener { // JFrame 主框架 private ImageIcon icon = null;// 主窗体图标 private JFrame mainFrame = null;// 主窗体 private JMenuBar menuBar = null;// 菜单栏 private JPanel mainPane = null;// 面板 private JTextArea textArea = null;// 文本域 private int maxRows = 25;// 文本域最大行数 private int maxColumns = 60;// 文本域最大列数 private JLabel state = null;// 状态栏:显示光标所在行数、列数 private JScrollPane scrollPane = null;// 滚动条 private JPopupMenu popupMenu; // 右键单击事件列表 private JFileChooser choose = null; // 文件对话框 private UndoManager undoManager;// 撤销管理类 private JDialog findDialog = null;// 查找对话框 private JDialog repalceDialog = null;// 替换对话框 private JDialog fontDialog = null;// 字体对话框 // 查找对话框组件
private JTextField fontKindTextField = null;// "字体"对话框"字体"input private JTextField font StyleTextField = null;// "字体"对话框"字形"input private JTextField font SizeTextField = null;// "字体"对话框"大小"input private JButton fontConfirmButton = null;// "字体"对话框"确定"按钮 private JComboBox fontKindComboBox = null;// "字体"对话框"字体"下拉列表 private JComboBox fontStyleComboBox = null;// "字体"对话框"字形"下拉列表 private JComboBox fontSizeComboBox = null;// "字体"对话框"大小"下拉列表 private JButton fontCancleButton = null;// "字体"对话框"取消"按钮 private JLabel fontNothingSecond = null;// "字体"对话框第四行占位组件 private JTextField fontExample = null;// "字体"对话框"实例"文本域 private JLabel fontNothingThrid = null;// "字体"对话框第四行占位组件
// 字体对话框组件 private String[] fontKind = null; private String[] fontStyle = { "PLAIN", "BOLD", "ITALIC" };// 常规、粗体、斜体 private String[] font Size = { "8", "10", "12", "14", "16"Байду номын сангаас "18", "20", "22", "24", "26", "28", "32", "36", "48", "72", "96" }; private String currentFontKind = "隶书"; private String currentFontStyel = "0"; private String currentFontSize = "20"; private JLabel fontKindLabel = null;// 字体 F private JLabel fontStyleLabel = null;// 字形 Y private JLabel fontSizeLabel = null;// 大小 S private JLabel fontNothingFirst = null;// "字体"对话框第一行占位组件
KeyListener,
private JLabel findTargetLabel = null;// 查找内容标签 private JTextField targetTextField = null;// 输入查找目标的 input private JButton findButton = null;// 查找按钮 private JCheckBox ignoreCaseCheckBox = null;// 区分大小写 private JPanel directionPanel = null;// 方向面板 private JRadioButton upRadioButton = null;// 向上单选按钮 private JRadioButton downRadioButton = null;// 向下单选按钮 private JButton cancleFindButton = null;// 取消按钮 private int startPosition = 0;// 查找开始时光标的位置 private int currentPosition = 0;// 查找当前光标的位置 private boolean isDownCase = true;// 是否默认向下 private boolean isIgnoreCase = true;// 是否区分大小写,默认不区分 true private Stack<Integer> matcherStack = null;// "向上"查找时用于储存匹配项开始索引的栈