@SuppressWarnings("deprecation")
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
{
fileDlg = new FileDialog(this,"OpenFile");
fileDlg.show();
fileName = fileDlg.getFile();
if(e.getSource()==exit)
System.exit(0);//
else if(e.getSource()==close)
ta.setText(null);
else if(e.getSource()==open)
add("Center",ta);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){System.exit(0);}});
ml.add(open);
FileDialog fileDlg;
String str,fileName;
byte byteBuf[]=new byte[10000];
TextArea ta = new TextArea(); enuItem exit = new MenuItem("exit");
@SuppressWarnings("deprecation")
TextEditor(){
setTitle("TextEditor");
setSize(600,400);
ta.setText(str);
setTitle("TextEditor-"+fileName);
}catch(IOException ioe){}
}
else if(e.getSource()==save){
close.addActionListener(this);
exit.addActionListener(this);
mb.add(ml);
setMenuBar(mb);
show();
}
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class TextEditor extends Frame implements ActionListener{
private static final long serialVersionUID = 1L;
try {
FileInputStream in = new FileInputStream(fileName);
in.read(byteBuf);
in.close();
str = new String (byteBuf);
Menu ml = new Menu("Menu");
MenuItem open = new MenuItem("open");
MenuItem close = new MenuItem("clear");
MenuItem save = new MenuItem("save");
out.close();
}catch (IOException ioe){}
}
}
public static void main (String args[]){
new TextEditor();
}
}
fileDlg= new FileDialog(this,"saveFile",FileDialog.SAVE);
fileDlg.show();
fileName = fileDlg.getFile();
str = ta.getText();
byteBuf = str.getBytes();
try{
FileOutputStream out = new FileOutputStream(fileName);
out.write(byteBuf);
ml.add(close);
ml.add(save);
ml.addSeparator();
ml.add(exit);
open.addActionListener(this);
save.addActionListener(this);