import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Hiirevajutus extends Applet implements MouseListener{ int x=100; int y=100; public Hiirevajutus(){ addMouseListener(this); } public void paint(Graphics g){ g.drawRect(x-5, y-5, 10, 10); } public void mousePressed(MouseEvent e){ /* x=e.getX(); y=e.getY(); */ //muutke programmi nõnda, et //ruut hüppab uude kohta vaid juhul, //kui kasutaja vajutab hiirega ruudu sisse if(e.getX()>x-5){ x=(int)(Math.random()*getWidth()); y=(int)(Math.random()*getHeight()); } repaint(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new Hiirevajutus()); f.setSize(200, 200); f.setVisible(true); } }