import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * Animation.java * * A class demonstrating Swing 2D graphics using a bouncing * ball. See Ball.java and AnimationPanel.java. */ public class Animation { public static void main(String[] args) { int width = 600; int height = 600; Color backgroundColor = Color.gray; // Create a AnimationPanel and give it a Ball. AnimationPanel panel = new AnimationPanel(); panel.setPreferredSize(new Dimension(width, height)); panel.setBackground(backgroundColor); panel.setBall(new Ball(200, 100, 50, 10, 10, Color.red)); // Create a JFrame and fill it with the AnimationPanel. JFrame worldFrame = new JFrame(); worldFrame.setContentPane(panel); worldFrame.pack(); worldFrame.setVisible(true); // Animate by alternately sleeping and stepping the AnimationPanel. while (true) { try { Thread.sleep(20); } catch (Exception e) { } panel.step(); } } }