这个不是我写的,不过先发到博客上来,保存着吧,之前写了好多的代码,重装系统的时候忘记备份了,都没了,那个心痛啊
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class TextEditor extends Frame implements
ActionListener{
private
static final long serialVersionUID = 1L;
FileDialog
fileDlg;
String
str,fileName;
byte
byteBuf[]=new byte[10000];
TextArea ta
= new TextArea();
MenuBar mb =
new MenuBar();
Menu ml =
new Menu("Menu");
MenuItem
open = new
MenuItem("open");
MenuItem
close = new
MenuItem("clear");
MenuItem
save = new
MenuItem("save");
MenuItem
exit = new
MenuItem("exit");
@SuppressWarnings("deprecation")
TextEditor(){
setTitle("TextEditor");
setSize(600,400);
add("Center",ta);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent
e){System.exit(0);}});
ml.add(open);
ml.add(close);
ml.add(save);
ml.addSeparator();
ml.add(exit);
open.addActionListener(this);
save.addActionListener(this);
close.addActionListener(this);
exit.addActionListener(this);
mb.add(ml);
setMenuBar(mb);
show();
}
@SuppressWarnings("deprecation")
@Override
public void
actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==exit)
System.exit(0);//
else if(e.getSource()==close)
ta.setText(null);
else if(e.getSource()==open)
{
fileDlg = new
FileDialog(this,"OpenFile");
fileDlg.show();