import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.math.*; public class kolmnurk extends Applet implements MouseListener{ int[] x = new int[3]; int[] y = new int[3]; int i=0; public void mousePressed(MouseEvent e){ //for(int i=0; i<3; i++){ x[i]=e.getX(); y[i]=e.getY(); i++; //}//for if (i==3) { joonistaKolmnurk(); } }//mousepressed public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void joonistaKolmnurk(){ double kylg1=0; double kylg2=0; double kylg3=0; double nurk1=0; double nurk2=0; double nurk3=0; int koht1x=0; int koht1y=0; int koht2x=0; int koht2y=0; int koht3x=0; int koht3y=0; Graphics g=this.getGraphics(); g.setColor(Color.blue); g.drawLine(x[0], y[0], x[1], y[1]); g.drawLine(x[1], y[1], x[2], y[2]); g.drawLine(x[2], y[2], x[0], y[0]); g.setColor(Color.black); kylg1=Math.round( Math.sqrt( (x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) )); koht1x=(x[1]+x[0])/2; koht1y=(y[1]+y[0])/2; g.drawString(kylg1+"", koht1x, koht1y); kylg2=Math.round( Math.sqrt( (x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]) )); koht2x=(x[2]+x[1])/2; koht2y=(y[2]+y[1])/2; g.drawString(kylg2+"", koht2x, koht2y); kylg3=Math.round( Math.sqrt( (x[0]-x[2])*(x[0]-x[2]) + (y[0]-y[2])*(y[0]-y[2]) )); koht3x=(x[0]+x[2])/2; koht3y=(y[0]+y[2])/2; g.drawString(kylg3+"", koht3x, koht3y); g.setColor(Color.green); nurk1=Math.round( 57.1 *Math.acos( (kylg1*kylg1+kylg2*kylg2-kylg3*kylg3)/(2*kylg1*kylg2) ) ); g.drawString(nurk1+"", x[1], y[1]); nurk2=Math.round( 57.1 *Math.acos( (kylg2*kylg2+kylg3*kylg3-kylg1*kylg1)/(2*kylg3*kylg2) ) ); g.drawString(nurk2+"", x[2], y[2]); nurk3=Math.round( 57.1 *Math.acos( (kylg1*kylg1+kylg3*kylg3-kylg2*kylg2)/(2*kylg3*kylg1) ) ); g.drawString(nurk3+"", x[0], y[0]); }//joonistakolmnurk public void init(){ TextField teade=new TextField("Kliki kolmnurga otspunktid!"); add(teade); addMouseListener(this); }//init }