import objectdraw.*; // a better basketball simulator public class BetterBasketball extends FrameWindowController { // placement of the text display private static final int TEXT_X = 100; private static final int TEXT_Y = 300; private static final int TEXT_SIZE = 16; // placement and sizing of the hoop private static final int HOOP_X = 150; private static final int HOOP_Y = 60; private static final int HOOP_WIDTH = 100; private static final int HOOP_HEIGHT = 60; // the Text object which displays the count private Text display; // the oval that represent the hoop private FramedOval hoop; // the number of points private int score; // initialize the counter and the text message public void begin() { score = 0; display = new Text("Take a shot.", TEXT_X, TEXT_Y, canvas); display.setFontSize(TEXT_SIZE); hoop = new FramedOval(HOOP_X, HOOP_Y, HOOP_WIDTH, HOOP_HEIGHT, canvas); } // increment the counter and update the text if player scores public void onMouseClick(Location point) { if (hoop.contains(point)) { score = score + 2; display.setText("You have scored " + score + " points."); } else { display.setText("Sorry, you missed!"); } } }