// Sample program that animates a ball. import java.awt.*; public class Ball1 { public static void main(String[] args) { double velocity = 300; // pixels per second double angle = 45; int seconds = 30; double xVelocity = velocity * Math.cos(Math.toRadians(angle)); double yVelocity = -velocity * Math.sin(Math.toRadians(angle)); DrawingPanel p = new DrawingPanel(600, 600); p.setBackground(Color.CYAN); Graphics g = p.getGraphics(); g.fillOval(295, 295, 10, 10); p.sleep(1000); double x = 300.0; double y = 300.0; for (int i = 1; i <= 10 * seconds; i++) { g.setColor(Color.WHITE); g.fillOval((int) x - 5, (int) y - 5, 10, 10); x += xVelocity / 10.0; y += yVelocity / 10.0; g.setColor(Color.BLACK); g.fillOval((int) x - 5, (int) y - 5, 10, 10); p.sleep(100); } } }