import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.text.*; import java.util.*; public class Jooned extends Applet implements ActionListener{ TextField tf=new TextField(10); TextField tf2=new TextField(10); TextField tf3=new TextField(10); TextField tf4=new TextField(10); TextField tf5=new TextField(38); Button b=new Button("Paralleelsus"); public Jooned(){ add(new Label("1. koordinaat")); add(tf); add(new Label("2. koordinaat")); add(tf2); add(new Label("3. koordinaat")); add(tf3); add(new Label("4. koordinaat")); add(tf4); add(b); add(tf5); b.addActionListener(this); } public void actionPerformed(ActionEvent e){ if(e.getSource()==b)ArvutaParaleelsus(); } public void ArvutaParaleelsus(){ double arv1,arv2,arv3,arv4,arv5,arv6,arv7,arv8; double k1,k2; try{ StringTokenizer stk=new StringTokenizer(tf.getText()); arv1=Double.parseDouble(stk.nextToken()); arv2=Double.parseDouble(stk.nextToken()); StringTokenizer stk2=new StringTokenizer(tf2.getText()); arv3=Double.parseDouble(stk2.nextToken()); arv4=Double.parseDouble(stk2.nextToken()); StringTokenizer stk3=new StringTokenizer(tf3.getText()); arv5=Double.parseDouble(stk3.nextToken()); arv6=Double.parseDouble(stk3.nextToken()); StringTokenizer stk4=new StringTokenizer(tf4.getText()); arv7=Double.parseDouble(stk4.nextToken()); arv8=Double.parseDouble(stk4.nextToken()); if(arv3-arv1==0 || arv7-arv5==0){ tf5.setText("Ei teki joont"); }else{ k1=(arv4-arv2)/(arv3-arv1); k2=(arv8-arv6)/(arv7-arv5); if(k1==k2){ tf5.setText("Paralleelsed "+k1+" "+k2); }else{ tf5.setText("Ei ole paralleelsed "+k1+" "+k2); } } }catch(Exception viga){ tf5.setText("valesti esitatud andmed"); } } public static void main(String argumendid[]){ Frame f=new Frame("Jooned"); f.setSize(400, 300); f.add(new Jooned()); f.setVisible(true); f.setLocation(300,300); f.addWindowListener(new Raami2kuular()); } } class Raami2kuular extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.out.println("Otsa sai"); System.exit(0); } }