📄 mynotepad.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class MyNotepad extends WindowAdapter implements ActionListener
{
Frame f;
Button btn;
TextArea ta;
String fileName;
public static void main(String argv[])
{
new MyNotepad(argv[0]);
}
public MyNotepad(String fileName)
{
this.fileName = fileName;
f = new Frame(fileName);
f.addWindowListener(this);
btn = new Button("保存文件");
btn.addActionListener(this);
ta = new TextArea(10,40);
f.add(ta, BorderLayout.CENTER);
f.add(btn, BorderLayout.SOUTH);
f.pack();
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
try {
FileOutputStream fout = new FileOutputStream(fileName);
byte buf[] = ta.getText().getBytes();
fout.write(buf);
fout.close();
}
catch (IOException ioe)
{
System.err.println(e);
}
}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -