// CS 1 demo program to play game of pong - no constraints on paddle import objectdraw.*; import java.awt.*; public class Pong extends WindowController{ // position and dimensions of the playing area private static final int COURT_LEFT = 50, COURT_TOP = 50, COURT_HEIGHT = 300, COURT_WIDTH = 250; // dimensions of the paddle private static final int PADDLE_WIDTH = 50, PADDLE_HEIGHT = 20; private FilledRect paddle; // the paddle private FramedRect boundary; // the boundary of the playing area. // make the playing area and paddle public void begin() { boundary = new FramedRect(COURT_LEFT, COURT_TOP, COURT_WIDTH, COURT_HEIGHT, canvas); paddle = new FilledRect(COURT_LEFT + (COURT_WIDTH-PADDLE_WIDTH)/2, COURT_TOP + COURT_HEIGHT - PADDLE_HEIGHT -1, PADDLE_WIDTH, PADDLE_HEIGHT, canvas); } // make a new ball when the player clicks public void onMouseClick(Location point) { new MovingBall(canvas, paddle, boundary); } // keep the edge of the paddle lined up with the mouse when it moves public void onMouseMove(Location point) { paddle.moveTo( point.getX(), COURT_TOP + COURT_HEIGHT - PADDLE_HEIGHT -1); } }