// Ekraanil on ring. Hiirega ringil klikkimisel sõidab ratas minema ja klikitud // punkt jätab jälje järgi. import java.awt.*; import java.awt.event.*; public class Ratas extends Frame implements MouseListener{ int ax, ay; int x=100; int y=100; int rkorgus=100; int rlaius=100; double nurk=0; double raadius=50; double samm=0.05; boolean status; public Ratas(){ // Frame f=new Frame("ratas"); pole vaja sest implements Frame setTitle("ratas"); setSize(500,300); setVisible(true); status=true; addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } //windowadapter ); //aken addMouseListener(this); } public void paint(Graphics g){ g.setColor(new Color(200,100,100)); g.setColor(Color.blue); g.fillOval(x,y,rkorgus,rlaius); g.setColor(Color.blue); } //class ratas public void mousePressed(MouseEvent e){ if (status=true){ status=false; ax=e.getX(); ay=e.getY(); Graphics g=getGraphics(); g.setColor(Color.white); g.fillRect(1,1,500,300); for(int x=ax; x<500; x=x+3){ y=ay; g.setColor(Color.white); g.fillRect(1,1,500,300); g.setColor(Color.red); g.fillOval(ax,ay,5,5); g.setColor(Color.blue); g.fillOval(x,y,rkorgus,rlaius); try{ Thread.sleep(1); } //try catch(Exception exp){ System.out.println("exception at sleep "); } //catch int px=((x+50)+(int)(raadius*Math.cos(nurk))-5); System.out.println(nurk); int py=((y+50)+(int)(raadius*Math.sin(nurk))-5); nurk=nurk+samm; if(nurk>2*Math.PI)nurk-=2*Math.PI; g.setColor(Color.black); g.fillOval(px, py, 4, 4); }//for for(int x=ax; x<500; x=x+3){ int px=((x+50)+(int)(raadius*Math.cos(nurk))-5); int py=((y+50)+(int)(raadius*Math.sin(nurk))-5); nurk=nurk+samm; if(nurk>2*Math.PI)nurk-=2*Math.PI; g.setColor(Color.black); g.fillOval(px, py, 4, 4); }//for }else{ System.out.println("else status false"); status=true; Graphics g=getGraphics(); g.fillRect(1,1,500,300); g.setColor(Color.blue); g.fillOval(x,y,rkorgus,rlaius); }//if status }//Mouseevent public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public void mouseClicked(MouseEvent e){} public static void main(String argumendid[]){ new Ratas(); } }