📄 记事本.java
字号:
package 我的;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.awt.datatransfer.*;
import java.util.*;
import javax.swing.JTextArea;
import javax.swing.JColorChooser;
import javax.swing.JScrollPane;
class 查找Dialog extends Dialog implements ActionListener
{
Label label;
TextField text;
Button button1,button2;
Checkbox box1,box2;
CheckboxGroup 方向;
static final int YES=1,NO=-1;
int message;
查找Dialog(Frame f,String s,boolean b)
{
super(f,s,b);
方向=new CheckboxGroup();
label=new Label("查找内容(N):");
text=new TextField();
Panel p1=new Panel();
p1.setLayout(new GridLayout(1,2));
p1.add(label);
p1.add(text);
box1=new Checkbox("向上(U)",false,方向);
box2=new Checkbox("向下(D)",true,方向);
Panel p2=new Panel();
p2.setLayout(new GridLayout(1,2));
p2.add(box1);
p2.add(box2);
Panel p3=new Panel();
p3.setLayout(new GridLayout(2,1));
p3.add(p1);
p3.add(p2);
button1=new Button("查找下一个");
button1.addActionListener(this);
button2=new Button("取消");
button2.addActionListener(this);
Panel p4=new Panel();
p4.setLayout(new GridLayout(2,1));
p4.add(button1);
p4.add(button2);
Panel p5=new Panel();
p5.setLayout(new GridLayout(1,2));
p5.add(p3);
p5.add(p4);
this.add(p5);
this.setSize(250,70);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
this.validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button1)
{
message=YES;
}
else if(e.getSource()==button2)
{
message=NO;
}
}
public int returnm()
{
return message;
}
}
class 替换Dialog extends Dialog implements ActionListener
{
Label label1,label2;
Checkbox box;
TextField text1,text2;
static final int YES=1,AND=0,OR=-1,NO=2;
Button 查找下一个,替换1,全部替换,取消;
int message;
替换Dialog(Frame f,String s,boolean b)
{
super(f,s,b);
label1=new Label("查找内容");
label2=new Label("替换内容");
text1=new TextField();
text2=new TextField();
box=new Checkbox("区分大小写");
查找下一个=new Button("查找下一个");
替换1=new Button("替换1");
全部替换=new Button("全部替换");
取消=new Button("取消");
Panel p1=new Panel();
p1.setLayout(new GridLayout(2,2));
p1.add(label1);
p1.add(text1);
p1.add(label2);
p1.add(text2);
Panel p2=new Panel();
p2.setLayout(new GridLayout(2,1));
p2.add(p1);
p2.add(box);
Panel p3=new Panel();
p3.setLayout(new GridLayout(4,1));
p3.add(查找下一个);
p3.add(替换1);
p3.add(全部替换);
p3.add(取消);
Panel p4=new Panel();
p4.setLayout(new GridLayout(1,2));
p4.add(p2);
p4.add(p3);
查找下一个.addActionListener(this);
替换1.addActionListener(this);
全部替换.addActionListener(this);
取消.addActionListener(this);
this.add(p4);
this.setSize(450,150);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
this.validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==查找下一个)
{
message=YES;this.setVisible(false);
}
else if(e.getSource()==替换1)
{
message=NO;this.setVisible(false);
}
else if(e.getSource()==全部替换)
{
message=AND;this.setVisible(false);
}
else if(e.getSource()==取消)
{
message=OR;this.setVisible(false);
}
}
public int returnMessage()
{
return message;
}
}
class myDialog extends Dialog implements ActionListener
{
Button 保存,不保存,取消;
Label text;
static final int YES=1,NO=0,OR=-1;
int message;
myDialog(Frame f,String s,boolean b)
{
super(f,s,b);
text=new Label("是否将更改保存");
保存=new Button("保存");
不保存=new Button("不保存");
取消=new Button("取消");
保存.addActionListener(this);
不保存.addActionListener(this);
取消.addActionListener(this);
this.setLayout(new BorderLayout());
this.add(text,BorderLayout.CENTER);
Panel p=new Panel();
p.add(保存);
p.add(不保存);
p.add(取消);
this.add(p,BorderLayout.SOUTH);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==保存)
{
message=YES;this.setVisible(false);
}
else if(e.getSource()==不保存)
{
message=NO;this.setVisible(false);
}
else if(e.getSource()==取消)
{
message=OR;this.setVisible(false);
}
}
public int getMessage()
{
return message;
}
}
class 字体1 extends Dialog implements ItemListener
{
Choice choice1;
Button 确定;
Button 取消;
Choice choice2;
Choice choice3;
String name,name1;
int i,i1;
int 大小,大小1;
字体1(Frame f,String s,boolean b)
{
super(f,s,b);
choice1=new Choice();
choice2=new Choice();
choice3=new Choice();
Button 确定=new Button("确定");
Button 取消=new Button("取消");
Panel p=new Panel();
p.setLayout(new GridLayout(1,2));
p.add(确定);p.add(取消);
GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
String fontname[]=ge.getAvailableFontFamilyNames();
for(int i=0;i<fontname.length;i++)
{
choice1.add(fontname[i]);
}
choice2.add("Font.BOLD");
choice2.add("Font.PLAIN");
choice2.add("Font.ITALIC");
choice2.add("Font.HANGING_BASELINE");
choice2.add("Font.ROMAN_BASELINE");
choice2.add("Font.CENTER_BASELINE");
choice2.add("Font.TRUETYPE_FONT");
choice3.add("7");
choice3.add("8");
choice3.add("9");
choice3.add("10");
choice3.add("11");
choice3.add("12");
choice3.add("13");
choice3.add("14");
choice3.add("15");
choice3.add("16");
choice3.add("17");
choice3.add("18");
choice3.add("19");
choice3.add("20");
choice3.add("22");
choice3.add("24");
choice3.add("26");
this.setSize(200,200);
this.setLayout(new GridLayout(4,1));
this.add(choice1);
this.add(choice2);
this.add(choice3);
this.add(p);
choice1.addItemListener(this);
choice2.addItemListener(this);
choice3.addItemListener(this);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
setVisible(false);
}
});
this.validate();
}
public void itemStateChanged(ItemEvent e)
{if(e.getItemSelectable()==choice1)
name1=choice1.getSelectedItem();
if(e.getItemSelectable()==choice2)
i1=choice2.getSelectedIndex();
if(e.getItemSelectable()==choice3)
大小1=Integer.parseInt(choice3.getSelectedItem());
}
}
class myFrame extends Frame implements ActionListener
{
MenuBar bar;
Menu 文件,编辑,格式,查看,帮助;
MenuItem 新建,打开,保存,另存为,页面设置,打印,退出;
MenuItem 撤销,剪切,复制,粘贴,删除,查找,查找下一个,替换,转到,全选,时间;
MenuItem 自动换行,字体,颜色;
MenuItem 状态栏;
MenuItem 查看帮助,关于记事本;
JTextArea text;
myDialog dialog;
Clipboard clipboard=null;
FileDialog file_save,file_load;
FileWriter tofile;
BufferedWriter out;
FileReader file_reader;
BufferedReader in;
Dimension dim;
JScrollPane scroll;
myFrame()
{ super("无标题-记事本");
clipboard=this.getToolkit().getSystemClipboard();
bar=new MenuBar();
文件=new Menu("文件");
编辑=new Menu("编辑");
格式=new Menu("格式");
查看=new Menu("查看");
帮助=new Menu("帮助");
新建=new MenuItem("新建");
打开=new MenuItem("打开");
保存=new MenuItem("保存");
另存为=new MenuItem("另存为");
页面设置=new MenuItem("页面设置");
打印=new MenuItem("打印");
退出=new MenuItem("退出");
撤销=new MenuItem("撤销");
剪切=new MenuItem("剪切");
复制=new MenuItem("复制");
粘贴=new MenuItem("粘贴");
删除=new MenuItem("删除");
查找=new MenuItem("查找");
查找下一个=new MenuItem("查找下一个");
替换=new MenuItem("替换");
转到=new MenuItem("转到");
全选=new MenuItem("全选");
时间=new MenuItem("时间");
自动换行=new MenuItem("自动换行");
字体=new MenuItem("字体");
颜色=new MenuItem("颜色");
状态栏=new MenuItem("状态栏");
查看帮助=new MenuItem("查看帮助");
关于记事本=new MenuItem("关于记事本");
文件.add(新建);
文件.add(打开);
文件.add(保存);
文件.add(另存为);
文件.add(页面设置);
文件.add(打印);
文件.add(退出);
编辑.add(撤销);
编辑.add(剪切);
编辑.add(复制);
编辑.add(粘贴);
编辑.add(删除);
编辑.add(查找);
编辑.add(查找下一个);
编辑.add(替换);
编辑.add(转到);
编辑.add(全选);
编辑.add(时间);
格式.add(自动换行);
格式.add(字体);
格式.add(颜色);
查看.add(状态栏);
帮助.add(查看帮助);
帮助.add(关于记事本);
bar.add(文件);
bar.add(编辑);
bar.add(格式);
bar.add(查看);
bar.add(帮助);
this.setMenuBar(bar);
新建.addActionListener(this);
打开.addActionListener(this);
保存.addActionListener(this);
另存为.addActionListener(this);
页面设置.addActionListener(this);
打印.addActionListener(this);
退出.addActionListener(this);
撤销.addActionListener(this);
剪切.addActionListener(this);
复制.addActionListener(this);
粘贴.addActionListener(this);
删除.addActionListener(this);
查找.addActionListener(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -