import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Liikumine1 extends JPanel implements ActionListener{ int x=100; int y=50; int d=15; Timer t=new Timer(500, this); public Liikumine1(){ t.start(); } public void paintComponent(Graphics g){ super.paintComponent(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){ JFrame f=new JFrame("Liikumine"); f.add(new Liikumine1()); f.setSize(300, 300); f.setVisible(true); } }