import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class TekstiRedaktor extends Applet implements ActionListener { Button edasi=new Button("Salvesta"); Button edasi2=new Button("Loe"); TextArea tf1= new TextArea(); TextArea tf3= new TextArea(); TextField tf2= new TextField("",20); int a=0; int mitu=0; int mitu2=0; int tahti=0; public TekstiRedaktor() { setLayout(new BorderLayout()); Panel p=new Panel(new GridLayout(1, 2)); p.add(edasi); p.add(edasi2); add(p, BorderLayout.NORTH); add(tf1, BorderLayout.WEST); add(tf2, BorderLayout.SOUTH); add(tf3, BorderLayout.CENTER); edasi.addActionListener(this); edasi2.addActionListener(this); } public void actionPerformed(ActionEvent e){ String aa=tf2.getText(); if(e.getSource()==edasi){ try{ PrintWriter valja=new PrintWriter( new FileWriter(aa) ); String yy=tf1.getText(); valja.println(yy); valja.close(); } catch(Exception w){} } if(e.getSource()==edasi2){ a=0; mitu=0; mitu2=0; tahti=0; tf3.setText(""); try{ BufferedReader sisse=new BufferedReader( new FileReader(aa) ); String dd=sisse.readLine(); while(dd!=null){ StringTokenizer st=new StringTokenizer(dd, " "); while(st.hasMoreTokens()){ String sona=st.nextToken(); mitu++; tahti=tahti+sona.length(); if((sona.endsWith(".")) || (sona.endsWith("!")) || (sona.endsWith("?"))) mitu2++; } tf1.append(dd+"\n"); a++; dd=sisse.readLine(); } tahti=tahti-mitu2; tf3.append("Tähti kokku "+tahti+"\n"); tf3.append("Ridasid "+a+"\n"); tf3.append("Sõnu "+mitu+"\n"); tf3.append("Lauseid "+mitu2+"\n"); } catch(Exception w){} } } public static void main(String argumendid[]){ Frame f=new Frame("-- TekstiRedaktor --"); f.add(new TekstiRedaktor()); f.setSize(700, 450); f.setBackground(Color.lightGray); f.setVisible(true); f.setResizable(false); f.addWindowListener(new LoppA()); } } class LoppA extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); } }