/* * */ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.*; /** * */ public class CorrectAnimation { /** * entry point, create an instance and pass on to createAndShowGUI() */ public static void main (String[] args) { final CorrectAnimation p = new CorrectAnimation(); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { p.createAndShowGUI(); } }); p.go(); } public void go() { for(int i = 0; i < 400; i++) { synchronized(this) { try { wait(10); } catch (InterruptedException e) { System.err.println("waiting interrupted ???\n\n" + e); } } _y++; if (_frame != null) _frame.repaint(); } } private JFrame _frame; /** * sets up everything, and then makes Frame visible */ public void createAndShowGUI() { //Create and set up the window. _frame = new JFrame("CorrectAnimation") { public void paint(Graphics g) { g.setColor(Color.BLUE); g.clearRect(0,0,400,400); g.fillOval(_x-_radius,_y-_radius,2*_radius,2*_radius); System.err.println("x " + _x + " y " + _y + " r " + _radius); } }; _frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); _frame.setPreferredSize(new Dimension(400,400)); _frame.pack(); _frame.setVisible(true); } private int _x = 200; private int _y = 0; private int _radius = 20; }