Computer Science 120
Introduction to Programming
Spring 2011, Siena College
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 * * Jim Teresco, Siena College, CSIS 120, Spring 2011 * * $Id: NiceBasketball.java 1516 2011-01-31 21:08:19Z 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); } }