import java.awt.*; import java.awt.geom.*; import java.awt.event.*; public class Punktiir1 extends Frame{ public static double x1,y1,x2,y2,dx,dy,ko1,ko2,ko3,ko4; public static int nr; public Punktiir1(){ setTitle("Vajuta hiirega!"); setSize(500, 500); setLocation(300, 100); setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); addMouseListener(new HiireKuular()); setVisible(true); } class HiireKuular extends MouseAdapter{ public void mousePressed(MouseEvent e){ nr=nr+1; Graphics agr=Punktiir1.this.getGraphics(); Graphics2D g=(Graphics2D)agr; if(nr==1){ x1=e.getX(); y1=e.getY();} else{ x2=e.getX(); y2=e.getY(); //JOONTE ALGUS dy=(y1-y2); dx=x1-x2; ko1=Math.abs(dx/dy); ko2=((dx)/(0.1+ko1)); ko3=dy/ko2; //VASAKULT PAREMALE if(x1x2){ double j=y1; for(double i=x1;i>x2;i--){ i=(i+0.9)-ko1; g.draw(new Line2D.Double(i,j,i-1,j-1)); j=j-ko3; } } //JOONTE LÕPP nr=0; }//NR else lõpp }//pressi lõpp } public static void main(String argumendid[]){ new Punktiir1(); } }