📄 mainsystem.java
字号:
startindex = a + b;
if(a == -1) {
JOptionPane.showMessageDialog(null, "没有你要查找的信息", "查找结果", 1);
a = 0;
startindex = 0;
}
textarea.select(a, startindex);
}
}
});
cbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!(textarea.getText().equals(""))) {
String replacestr = cfield.getText();
textarea.replaceSelection(replacestr);
}
else {
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(jd,"记事本为空,无法替换","警告",JOptionPane.OK_OPTION);
}
}
});
cabutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!(textarea.getText().equals(""))) {
while(a > -1) {
String textstr = textarea.getText();
String searchstr = sfield.getText();
a = textstr.indexOf(searchstr, startindex);
if(a == -1)
break;
b = searchstr.length();
startindex = a + b;
textarea.select(a, startindex);
textarea.replaceSelection(cfield.getText());
startindex = a + b;
}
JOptionPane.showMessageDialog(null, "全部替换完毕", "替换", 1);
a = 0;
startindex = 0;
}
else {
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(jd,"记事本为空,无法替换","警告",JOptionPane.OK_OPTION);
}
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
jd.dispose();
}
});
jd.setVisible(true);
}
if(evt.getActionCommand().equals("全选")) {
textarea.selectAll();
}
if(evt.getActionCommand().equals("时间/日期")) {
final JDialog jd = new JDialog(this, "插入日期");
Container pane = jd.getContentPane();
pane.setLayout(new GridLayout(2, 1));
jd.setSize(370, 100);
jd.setLocation(200, 300);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel1.setLayout(new FlowLayout());
panel2.setLayout(new GridLayout(1, 3, 5, 5));
JLabel label = new JLabel("插入内容:");
final JTextField sfield = new JTextField(20);
sfield.setEditable(false);
JButton insert = new JButton("确定");
ButtonGroup group = new ButtonGroup();
final JRadioButton j1 = new JRadioButton("格式一", true);
final JRadioButton j2 = new JRadioButton("格式二");
final JRadioButton j3 = new JRadioButton("格式三");
group.add(j1);
group.add(j2);
group.add(j3);
GregorianCalendar day = new GregorianCalendar();
final String time1 = day.getTime().toString();
sfield.setText(time1);
Calendar cal = Calendar.getInstance();
Formatter fmt1 = new Formatter();
fmt1.format("%tc", cal);
final String time2 = fmt1.toString();
Formatter fmt2 = new Formatter();
fmt2.format("%tF %tT", cal, cal);
final String time3 = fmt2.toString();
panel1.add(label);
panel1.add(sfield);
panel1.add(insert);
panel2.add(j1);
panel2.add(j2);
panel2.add(j3);
pane.add(panel1);
pane.add(panel2);
jd.setVisible(true);
j1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sfield.setText(time1);
}
});
j2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sfield.setText(time2);
}
});
j3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sfield.setText(time3);
}
});
insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String ss = sfield.getText();
int position = textarea.getCaretPosition();
textarea.insert(ss, position);
jd.dispose();
}
});
}
if(evt.getActionCommand().equals("自动换行")) {
if(jcbmi.getState()) {
textarea.setLineWrap(true);
textarea.setWrapStyleWord(true);
}
else {
textarea.setLineWrap(false);
textarea.setWrapStyleWord(false);
}
}
if(evt.getActionCommand().equals("字体")) {
final JDialog fontdialog = new JDialog(this, "设置字体");
Container pane = fontdialog.getContentPane();
pane.setLayout(new GridLayout(3, 1));
fontdialog.setSize(210, 220);
fontdialog.setLocation(200, 300);
JPanel panel1 = new JPanel();
JLabel label1 = new JLabel("字型", JLabel.RIGHT);
JLabel label2 = new JLabel("大小", JLabel.LEFT);
final JComboBox jb1 = new JComboBox();
final JComboBox jb2 = new JComboBox();
jb1.addItem("常规");
jb1.addItem("粗体");
jb1.addItem("斜体");
jb1.addItem("粗斜体");
jb2.addItem("12");
jb2.addItem("8");
jb2.addItem("16");
jb2.addItem("20");
jb2.addItem("30");
jb2.addItem("40");
panel1.add(label1);
panel1.add(jb1);
panel1.add(label2);
panel1.add(jb2);
JPanel panel2 = new JPanel();
JButton ok = new JButton("确定");
JButton cancel = new JButton("取消");
panel2.add(ok);
panel2.add(cancel);
JPanel panel3 = new JPanel();
panel3.setLayout(new BorderLayout());
JLabel label3 = new JLabel("预览:");
String showstr = "晓春记事本";
final JTextArea showfield = new JTextArea(showstr);
showfield.setEditable(false);
panel3.add(label3, BorderLayout.WEST);
panel3.add(showfield, BorderLayout.CENTER);
pane.add(panel1);
pane.add(panel2);
pane.add(panel3);
fontdialog.setVisible(true);
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(jb1.getSelectedItem().equals("常规")) {
int fontsize = Integer.parseInt((String) jb2.getSelectedItem());
Font f = new Font("Dialog", Font.PLAIN, fontsize);
showfield.setFont(f);
}
if(jb1.getSelectedItem().equals("粗体")) {
int fontsize = Integer.parseInt((String) jb2.getSelectedItem());
Font f = new Font("Dialog", Font.BOLD, fontsize);
showfield.setFont(f);
}
if(jb1.getSelectedItem().equals("斜体")) {
int fontsize = Integer.parseInt((String) jb2.getSelectedItem());
Font f = new Font("Dialog", Font.ITALIC, fontsize);
showfield.setFont(f);
}
if(jb1.getSelectedItem().equals("粗斜体")) {
int fontsize = Integer.parseInt((String) jb2.getSelectedItem());
Font f = new Font("Dialog", Font.BOLD + Font.ITALIC, fontsize);
showfield.setFont(f);
}
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(jb2.getSelectedItem().equals("12")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 12);
showfield.setFont(f);
}
if(jb2.getSelectedItem().equals("8")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 8);
showfield.setFont(f);
}
if(jb2.getSelectedItem().equals("16")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 16);
showfield.setFont(f);
}
if(jb2.getSelectedItem().equals("20")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 20);
showfield.setFont(f);
}
if(jb2.getSelectedItem().equals("30")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 30);
showfield.setFont(f);
}
if(jb2.getSelectedItem().equals("40")) {
Font a = showfield.getFont();
int style = a.getStyle();
Font f = new Font("Dialog", style, 40);
showfield.setFont(f);
}
}
});
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Font a = showfield.getFont();
int style = a.getStyle();
int size = Integer.parseInt((String) jb2.getSelectedItem());
Font f = new Font("Dialog", style, size);
textarea.setFont(f);
fontdialog.dispose();
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fontdialog.dispose();
}
});
}
if(evt.getActionCommand().equals("关于记事本")) {
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(this," 晓春记事本 2008-05-7","关于记事本",JOptionPane.OK_OPTION);
}
}
class UndoHander implements UndoableEditListener {
public void undoableEditHappened(UndoableEditEvent eundo) {
undo.addEdit(eundo.getEdit());
}
}
public static void main(String[] args) {
new MainSystem();
System.gc();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -