import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Liikumine1 extends Applet implements ActionListener, MouseListener{ int x=100; int y=50; int d=15; Timer t=new Timer(500, this); public Liikumine1(){ t.start(); addMouseListener(this); } public void paint(Graphics g){ super.paint(g); g.drawRect(x, y, d, d); } public void liigu(){ x=x+1; repaint(); } public void actionPerformed(ActionEvent e){ if(e.getSource()==t){ liigu(); } } public void mousePressed(MouseEvent e){ x=e.getX(); y=e.getY(); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} //Ühendage hiire näitega. //Ruut kukub sellest kohast alla kuhu vajutati public static void main(String[] arg){ Frame f=new Frame("Liikumine"); f.add(new Liikumine1()); f.setSize(300, 300); f.setVisible(true); } }