import java.io.*; import java.util.StringTokenizer; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; public class tekstiredaktor extends Frame implements ActionListener{ Button save=new Button("Salvesta"); Button open=new Button("Ava"); Button uus=new Button("Uus"); Button cut=new Button("Lõika"); Button copy=new Button("Kopeeri"); Button paste=new Button("Kleebi"); Button arv=new Button("Sõnade arv"); Frame sona=new Frame(); Button ok=new Button("OK"); TextField number=new TextField("0"); TextArea tekst=new TextArea(); //nurgast kinnipanek Frame kysim=new Frame(); Button jah=new Button("Jah"); Button ei=new Button("Ei"); //uus leht Frame uusleht=new Frame(); Button uusjah=new Button("Jah"); Button uusei=new Button("Ei"); //tavaline savemine Frame kysim2=new Frame(); Button jah2=new Button("Jah"); Button tyhista2=new Button("Tühista"); TextField nimi2=new TextField("Kirjuta siia faili nimi!"); //open TextArea failid=new TextArea(); Frame kysim3=new Frame(); Button jah3=new Button("Jah"); Button tyhista3=new Button("Tühista"); TextField nimi3=new TextField("Kirjuta siia faili nimi!"); //error Frame error=new Frame(); Button errorjah=new Button("Salvesta ikka"); Button errorei=new Button("Tühista"); public tekstiredaktor(){ setTitle("Tekstiredaktor"); setSize(500,600); Panel paneel=new Panel(new GridLayout(2,1)); Panel paneel2=new Panel(new FlowLayout()); paneel.setLayout(new BorderLayout()); paneel.add(paneel2, BorderLayout.NORTH); paneel.add(tekst); Panel paneel3=new Panel(new FlowLayout()); paneel2.setLayout(new BorderLayout()); paneel2.add(paneel3, BorderLayout.WEST); paneel3.add(uus); paneel3.add(save); paneel3.add(open); paneel3.add(cut); paneel3.add(copy); paneel3.add(paste); paneel3.add(arv); uus.addActionListener(this); save.addActionListener(this); open.addActionListener(this); cut.addActionListener(this); copy.addActionListener(this); paste.addActionListener(this); arv.addActionListener(this); add(paneel); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim.setVisible(true); } } ); setVisible(true); //nurgast kinnipanek kysim.setSize(300,70); Panel savep=new Panel(new GridLayout(2,1)); kysim.setTitle("Kas tahad programmist väljuda?"); jah.addActionListener(this); ei.addActionListener(this); savep.add(jah); savep.add(ei); kysim.add(savep); kysim.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim.setVisible(false); } } ); //uus uusleht.setSize(300,70); Panel uusp=new Panel(new GridLayout(2,1)); uusleht.setTitle("Kas tahad tühja lehte?"); uusjah.addActionListener(this); uusei.addActionListener(this); uusp.add(uusjah); uusp.add(uusei); uusleht.add(uusp); uusleht.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ uusleht.setVisible(false); } } ); //tavaline savemine kysim2.setSize(300,90); Panel savep2=new Panel(new GridLayout(3,1)); kysim2.setTitle("Kas tahad salvestada?"); jah2.addActionListener(this); tyhista2.addActionListener(this); savep2.add(nimi2); savep2.add(jah2); savep2.add(tyhista2); kysim2.add(savep2); kysim2.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim2.setVisible(false); } } ); //open kysim3.setSize(300,200); kysim3.setTitle("Kas tahad faili avada?"); Panel openp=new Panel(new GridLayout(2,1)); Panel openp2=new Panel(new GridLayout(3,1)); openp2.setSize(300,90); jah3.addActionListener(this); tyhista3.addActionListener(this); openp2.add(nimi3); openp2.add(jah3); openp2.add(tyhista3); openp.setLayout(new BorderLayout()); openp.add(openp2, BorderLayout.SOUTH); openp.add(failid); kysim3.add(openp); kysim3.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ kysim3.setVisible(false); } } ); //error error.setSize(300,70); error.setTitle("Selline fail on juba olemas!!"); Panel errorp=new Panel(new GridLayout(2,1)); errorjah.addActionListener(this); errorei.addActionListener(this); errorp.add(errorjah); errorp.add(errorei); error.add(errorp); error.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ error.setVisible(false); } } ); //sõnade arv sona.setSize(225,50); sona.setTitle("Määra sõnade arv reas!"); Panel reas=new Panel(new GridLayout(1,2)); ok.addActionListener(this); reas.add(number); reas.add(ok); sona.add(reas); sona.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ sona.setVisible(false); } } ); } public void actionPerformed(ActionEvent e){ //nurgast kinnipanek if(e.getSource()==jah){ System.exit(0); } if(e.getSource()==ei){ kysim.setVisible(false); } //error if (e.getSource()==errorjah){ try{ String fnimi=nimi2.getText(); String jutt=tekst.getText(); File jutud=new File("Jutud"); if(!jutud.isDirectory()){ jutud.mkdir(); } PrintWriter faili=new PrintWriter( new FileWriter("Jutud"+File.separator+fnimi+".txt") ); StringTokenizer stk=new StringTokenizer(jutt, "\n"); while(stk.hasMoreTokens()){ faili.println(stk.nextToken()+"\n"); } faili.close(); } catch(Exception viga){} error.setVisible(false); } if(e.getSource()==errorei){ error.setVisible(false); kysim2.setVisible(true); } //tavaline savemine if(e.getSource()==save){ kysim2.setVisible(true); } if(e.getSource()==jah2){ try{ String fnimi=nimi2.getText(); File kataloog=new File("Jutud"); String[] nimed=kataloog.list(); String tulemus=""; for(int i=0; i=0){ error.setVisible(true); } else{ String jutt=tekst.getText(); File jutud=new File("Jutud"); if(!jutud.isDirectory()){ jutud.mkdir(); } PrintWriter faili=new PrintWriter( new FileWriter("Jutud"+File.separator+fnimi+".txt") ); StringTokenizer stk=new StringTokenizer(jutt, "\n"); while(stk.hasMoreTokens()){ faili.println(stk.nextToken("\n")); } faili.close(); } } catch(Exception viga){} kysim2.setVisible(false); } if(e.getSource()==tyhista2){ kysim2.setVisible(false); } //open if(e.getSource()==open){ File kataloog=new File("Jutud"); String[] nimed=kataloog.list(); String tulemus=""; for(int i=0; i