import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Liikumine1 extends Applet implements ActionListener{ int x=100; int y=50; int d=15; Timer t=new Timer(500, this); public Liikumine1(){ t.start(); } 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 static void main(String[] arg){ Frame f=new Frame("Liikumine"); f.add(new Liikumine1()); f.setSize(300, 300); f.setVisible(true); } }