import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class kolmnurk2 extends Applet implements ActionListener{ int x=50, y=60; int roheline=0, sinine=0,punane=0; public kolmnurk2(){ addMouseListener(new HiireKuular());//reageerib hiire klõpsule// } public void kolmnurk(){ Graphics ekraan=getGraphics(); setBackground(Color.white); int x=(int)(Math.random()*800); //tipp int y=(int)(Math.random()*800); //tipp int k6rgus=(int)(Math.random()*800);//suvaline kõrgus int alus=2*k6rgus/3*3; int poolalust=alus/2; int k6rgusealusx=x; int k6rgusealusy=y+k6rgus; int vasakx=k6rgusealusx-poolalust; int paremx=k6rgusealusx+poolalust; int vasaky=k6rgusealusy; int paremy=k6rgusealusy; int r=(int)(Math.random()*250); //värv int p=(int)(Math.random()*250); //värv int s=(int)(Math.random()*250); //värv ekraan.setColor(new Color(roheline+r,punane+p,sinine+s)); int xd[]=new int[3]; xd[0]=x; xd[1]=vasakx; xd[2]=paremx; int yd[]=new int[3]; yd[0]=y; yd[1]=paremy; yd[2]=vasaky; ekraan.fillPolygon(xd,yd,3); try{ Thread.sleep(20); //System.exit(0); //veakood 0 }catch(Exception e){} //ekraan.fillOval(x, y, diameeter, diameeter); } class HiireKuular extends MouseAdapter{ public void mousePressed(MouseEvent e){ while (x>0){ kolmnurk(); } } } public void actionPerformed(ActionEvent e){ repaint(); } public static void main(String argumendid[]){ Frame f=new Frame(); f.add(new kolmnurk2()); f.setSize(800, 800); f.setVisible(true); } }