// StickGame.java import java.awt.*; import javax.swing.*; public class StickGame extends JApplet { //a StickGame object "has-a" Stick object: composition: software reuse: //use the stick, don't reinvent it. Stick s1, s2, s3; public void init() { //instantiate some Stick objects, using various constructors. //Don't know how the Sticks work (i.e. their implementation), // only what they do (i.e. their interface, public methods) s1 = new Stick(); s2 = new Stick( 50, 20, new Point(100,100), 45 ); s3 = new Stick( s2 ); //senseless here, but to get rid of an object, set its reference to null //(or assign another Stick object to s1) s1 = null; //will be automatically garbage collected, eventually } public void paint( Graphics g ) { super.paint( g ); s1.draw( g ); s2.draw( g ); } }