Computer Science 252
Problem Solving with Java
Fall 2013, The College of Saint Rose
NiceBasketball Demo
A working demo of NiceBasketball will appear below. Click inside the applet to interact with it.
NiceBasketball BlueJ Project
Click here to download a BlueJ project for NiceBasketball.
NiceBasketball Source Code
The Java source code for NiceBasketball is below. Click on a file name to download it.
import objectdraw.*; import java.awt.*; /* * Example NiceBasketball - a lovely basketball that just * sits there. * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * The College of Saint Rose, Fall 2013 * * $Id: NiceBasketball.java 2218 2013-10-18 14:06:39Z terescoj $ */ public class NiceBasketball extends WindowController { // the color to draw the ball private static final Color BALL_ORANGE = new Color(250, 85, 10); // size and starting angles for cut arc in degrees private static final int CUTSIZE = 100; private static final int RIGHTCUTSTART = 90 + (180 - CUTSIZE) / 2; private static final int LEFTCUTSTART = 270 + (180 - CUTSIZE) / 2; // the orange part of the ball private FilledOval body; // the border of the ball private FramedOval border; // the two curves on the sides of the ball private FramedArc leftCut, rightCut; // the vertical and horizontal lines through the ball private Line vert, horiz; // ball position and size private static final int BALL_LEFT = 175; private static final int BALL_TOP = 175; private static final int BALL_SIZE = 50; public void begin() { // draw the circles that make it look like a ball body = new FilledOval(BALL_LEFT, BALL_TOP, BALL_SIZE, BALL_SIZE, canvas); body.setColor(BALL_ORANGE); border = new FramedOval(BALL_LEFT, BALL_TOP, BALL_SIZE, BALL_SIZE, canvas); // draw the lines and arcs that make it look like a basketball rightCut = new FramedArc(BALL_LEFT + BALL_SIZE * 2 / 3, BALL_TOP, BALL_SIZE, BALL_SIZE, RIGHTCUTSTART, CUTSIZE, canvas); leftCut = new FramedArc(BALL_LEFT - BALL_SIZE * 2 / 3, BALL_TOP, BALL_SIZE, BALL_SIZE, LEFTCUTSTART, CUTSIZE, canvas); vert = new Line(BALL_LEFT + BALL_SIZE / 2, BALL_TOP, BALL_LEFT + BALL_SIZE / 2, BALL_TOP + BALL_SIZE, canvas); horiz = new Line(BALL_LEFT, BALL_TOP + BALL_SIZE / 2, BALL_LEFT + BALL_SIZE, BALL_TOP + BALL_SIZE / 2, canvas); } }