import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Joon extends Applet implements ActionListener{ TextField x11=new TextField(""); TextField y11=new TextField(""); TextField x21=new TextField(""); TextField y21=new TextField(""); TextField x12=new TextField(""); TextField y12=new TextField(""); TextField x22=new TextField(""); TextField y22=new TextField(""); TextField para=new TextField(""); int algX1 = 0, algY1 = 0, loppX1 = 0, loppY1 = 0, algX2 = 0, algY2 = 0, loppX2 = 0, loppY2 = 0, x0 = 125, y0 = 165; public void paint(Graphics g) { g.setColor(Color.gray); g.drawLine(x0 - 100, y0, x0 + 100, y0); g.drawLine(x0, y0 - 100, x0, y0 + 100); g.setColor(Color.black); g.drawLine(x0 + (algX2), y0 - (algY2), x0 + (loppX2), y0 - (loppY2)); g.setColor(Color.red); g.drawLine(x0 + (algX1), y0 - (algY1), x0 + (loppX1), y0 - (loppY1)); } public void init() { setLayout(new BorderLayout()); Panel p1=new Panel(new GridLayout(1, 4)); Panel p2=new Panel(new GridLayout(2, 4)); Panel p3=new Panel(new GridLayout(2, 4)); Label tekst1=new Label("x1", Label.CENTER); Label tekst2=new Label("x2", Label.CENTER); Label tekst3=new Label("x3", Label.CENTER); Label tekst4=new Label("x4", Label.CENTER); Label tekst5=new Label("y1", Label.CENTER); Label tekst6=new Label("y2", Label.CENTER); Label tekst7=new Label("y3", Label.CENTER); Label tekst8=new Label("y4", Label.CENTER); p2.add(tekst1); p2.add(x11); p2.add(tekst5); p2.add(y11); p2.add(tekst2); p2.add(x21); p2.add(tekst6); p2.add(y21); p1.add(p2); p3.add(tekst3); p3.add(x12); p3.add(tekst7); p3.add(y12); p3.add(tekst4); p3.add(x22); p3.add(tekst8); p3.add(y22); p1.add(p3); add(p1, BorderLayout.NORTH); add(para, BorderLayout.SOUTH); x11.addActionListener(this); y11.addActionListener(this); x21.addActionListener(this); y21.addActionListener(this); x12.addActionListener(this); y12.addActionListener(this); x22.addActionListener(this); y22.addActionListener(this); } public void actionPerformed(ActionEvent e) { double tous1, tous2, tousuVahe, ax1, ay1, lx1, ly1, ax2, ay2, lx2, ly2; para.setText(""); algX1 = (numbriks(x11)); algY1 = (numbriks(y11)); loppX1 = (numbriks(x21)); loppY1 = (numbriks(y21)); algX2 = (numbriks(x12)); algY2 = (numbriks(y12)); loppX2 = (numbriks(x22)); loppY2 = (numbriks(y22)); ax1 = algX1; ay1 = algY1; lx1 = loppX1; ly1 = loppY1; ax2 = algX2; ay2 = algY2; lx2 = loppX2; ly2 = loppY2; tous1 = ((ay1 - ly1) / (ax1 - lx1)); tous2 = ((ay2 - ly2) / (ax2 - lx2)); repaint(); if (tous1 == tous2) { para.setText("Jooned on paraleelsed"); } } int numbriks(TextField tf) { return Integer.parseInt(tf.getText().trim()); } }