import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.io.*; public class Redaktor1 extends Applet implements ActionListener{ TextArea tekstiala=new TextArea(); Button loe=new Button("Loe"); Button salvesta=new Button("Salvesta"); String failinimi="andmed.txt"; public Redaktor1(){ setLayout(new BorderLayout()); add(tekstiala, BorderLayout.CENTER); Panel nupupaneel=new Panel(new GridLayout(1, 2)); nupupaneel.add(loe); nupupaneel.add(salvesta); add(nupupaneel, BorderLayout.SOUTH); loe.addActionListener(this); salvesta.addActionListener(this); } public void actionPerformed(ActionEvent e){ try{ if(e.getSource()==salvesta){ PrintWriter faili=new PrintWriter(new FileWriter(failinimi)); faili.print(tekstiala.getText()); faili.close(); } if(e.getSource()==loe){ BufferedReader failist=new BufferedReader(new FileReader(failinimi)); String rida=failist.readLine(); tekstiala.setText(""); while(rida!=null){ tekstiala.append(rida+"\r\n"); rida=failist.readLine(); } failist.close(); } }catch(Exception viga){ viga.printStackTrace(); } } public static void main(String[] arg){ Frame f=new Frame("Tekstiredaktor"); f.add(new Redaktor1()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }