import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.lang.String; import java.util.StringTokenizer; public class text extends Applet implements ActionListener{ TextField tf1=new TextField("Sisesta siia faili nimi!", 50); TextField tf2=new TextField("Siia tuleb tulemus.", 50); TextArea ta1=new TextArea(5,50); public text(){ add(tf1); add(tf2); add(ta1); tf1.addActionListener(this); } public void actionPerformed(ActionEvent e){ int i=1; //lause number int j=0; //sõnade arv lauses int k=0; //max sõnade arv int l=0; //pikim lause int m=0; //pikima lause sõnade arv String abilause=""; //vahepealne lause salvestamise koht String lause=""; //lõplik lause try{ BufferedReader sisse=new BufferedReader( new FileReader(tf1.getText()) ); String mass=""; String rida=sisse.readLine(); while(rida!=null){ mass=mass+" "+rida; rida=sisse.readLine(); } sisse.close(); StringTokenizer st=new StringTokenizer(mass, " "); while(st.hasMoreTokens()){ String sona=st.nextToken(); System.out.println(sona); if(sona.endsWith(".")){ abilause=abilause+" "+sona; j=j+1; if(j>k){lause=abilause;m=j;l=i;k=j;} abilause=""; j=0; System.out.println("lause "+i+" >> "+lause); i=i+1; }else{ abilause=abilause+" "+sona; j=j+1; } } }catch(Exception viga){ viga.printStackTrace(); } tf2.setText("Kõige suurema sõnade arvuga ("+m+") on lause nr "+l+"."); ta1.setText("Lause ise on >>\n"+lause); } public static void main(String argumendid[]) throws IOException{ Frame f=new Frame("Faili analüüs"); f.setSize(400, 190); f.add(new text()); f.setVisible(true); } }