import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.applet.Applet; import java.io.*; public class Redaktor2 extends JApplet implements ActionListener{ JTextArea tekstiala=new JTextArea(); JButton loe=new JButton("Loe"); JButton salvesta=new JButton("Salvesta"); String failinimi="andmed.txt"; public Redaktor2(){ //setLayout(new BorderLayout()); getContentPane().add(new JScrollPane(tekstiala, JScrollPane.VERTICAL_SCROLLBAR_NEVER , JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS ), BorderLayout.CENTER); JPanel nupupaneel=new JPanel(new GridLayout(1, 2)); nupupaneel.add(loe); nupupaneel.add(salvesta); getContentPane().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){ JFrame f=new JFrame("Tekstiredaktor"); f.getContentPane().add(new Redaktor2()); f.setSize(300, 300); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }