// // Broken, as the animation inside the actionPerformed() // method blocks all repainting // import java.awt.*; import java.awt.event.*; public class BrokenSleepExample extends Frame { private Rectangle position; private static BrokenSleepExample ex; private BrokenSleepExample () { setSize(400, 400); setTitle("Sleep Example"); position = new Rectangle(150, 0, 100, 100); Button button = new Button("Fall"); button.addActionListener(new ExampleActionListener()); add("North", button); } private class ExampleActionListener implements ActionListener { public void actionPerformed (ActionEvent e) { try { position = new Rectangle(150, 0, 100, 100); while (position.y < 400) { position.y = position.y + 10; System.out.println("Position.y: " + position.y); ex.test(); Thread.sleep(10); } } catch (Exception ex) { System.out.println("Exception: " + ex); } } } public void test () { System.out.println("TEST!"); repaint(); } public void paint (Graphics g) { System.out.println("PAINT!"); g.setColor(Color.blue); g.fillOval(position.x, position.y, position.width, position.height); } public static void main (String[] args) { ex = new BrokenSleepExample(); ex.show(); } }