/** *@author Herki Sula */ import java.awt.*; import java.util.Date; import java.awt.event.*; import javax.swing.*; public class Sonavordlus2{ public static void main(String argumendid[]){ final String sonad[]={"demo","saadab","eestkoste","vabadus","kataloog","dilemma","kanarbik","susla","piraat","modem"}; final Frame f=new Frame("rama"); final Panel p=new Panel(new GridLayout(2,1)); final JLabel silt=new JLabel("
Mine teise tekstivälja ja sisesta sinna
"+ "ülemises lahtris olnud sõna."); final TextField tf1=new TextField(sonad[0]); final TextField tf2=new TextField(""); f.setSize(400,200); f.setLocation(300,100); f.setTitle("Sõnavõrdlus"); p.add(tf1); p.add(tf2); f.add(p,BorderLayout.NORTH); f.add(silt,BorderLayout.CENTER); f.setVisible(true); tf2.addActionListener(new ActionListener(){ int l=0,ri=0,fa=0; long algus,lopp,vahe; public void actionPerformed(ActionEvent e){ try{ if(ri==0){ algus=new Date().getTime(); } if(ri==sonad.length-1){ lopp=new Date().getTime(); vahe=lopp-algus; } String tf1st; String tf2st; tf2st=tf2.getText(); tf1st=tf1.getText(); if(tf2st.equalsIgnoreCase(tf1st)){ silt.setText("Sõna sobis täpselt"); System.out.println("OK"); ri++; } if(!(tf2st.equalsIgnoreCase(tf1st))){ l--; fa++; silt.setText("Sõna polnud see"); System.out.println("NOT OK"); } if(l==sonad.length-1){ Thread.sleep(2000); silt.setText("Sul kulus 10 sõna õigeks järeletrükiks "+(int)(vahe/1000)+" sekundit
"+ "Valesti sisestasid "+fa+" korda."); } l++; String sona=sonad[l]; tf1.setText(sona); tf2.setText(""); }catch(Exception r){ } } }); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }