Computer Science 252
Problem Solving with Java
Spring 2015, 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, Spring 2014 * * $Id: NiceBasketball.java 2311 2014-01-23 05:03:17Z 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; // 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 new FilledOval(BALL_LEFT, BALL_TOP, BALL_SIZE, BALL_SIZE, canvas).setColor(BALL_ORANGE); new FramedOval(BALL_LEFT, BALL_TOP, BALL_SIZE, BALL_SIZE, canvas); // draw the lines and arcs that make it look like a basketball new FramedArc(BALL_LEFT + BALL_SIZE * 2 / 3, BALL_TOP, BALL_SIZE, BALL_SIZE, RIGHTCUTSTART, CUTSIZE, canvas); new FramedArc(BALL_LEFT - BALL_SIZE * 2 / 3, BALL_TOP, BALL_SIZE, BALL_SIZE, LEFTCUTSTART, CUTSIZE, canvas); new Line(BALL_LEFT + BALL_SIZE / 2, BALL_TOP, BALL_LEFT + BALL_SIZE / 2, BALL_TOP + BALL_SIZE, canvas); new Line(BALL_LEFT, BALL_TOP + BALL_SIZE / 2, BALL_LEFT + BALL_SIZE, BALL_TOP + BALL_SIZE / 2, canvas); } }