An Applet Animation
This project makes use of the Objectdraw library, created by faculty at Williams College to make it easier to create applets.
This method draws a button which, when clicked, starts the animation. The FilledRect class creates a filled-in rectangle; for example:
rect = new FilledRect(50, 50, 200, 250, canvas);
where (50, 50) are the coordinates of the upper-left hand corner of the rectangle, 200 is the width, 250 is the height, and 'canvas' is built into Objectdraw and represents the screen.
The Text class creates text on the screen, for example:
Text yup = new Text("Thursday", 50, 100, canvas);
draws "Thursday" beginning at the point (50, 100).
The Font class (part of Java, not Objectdraw) allows you to change the font. The '.setColor()' method allows you to change the color. For example:
Font myFont = new Font("SansSerif",Font.BOLD, 12);
Use these classes to create a button. (Changing the Font and Color are optional.)
Objectdraw includes a '.contains()' method that is true if an object 'contains' a given Location. Modify this method so that it runs only if the Location of the mouse click is inside the button you created.
This method executes when the 'start()' method is encountered in the constructor 'HangGlider()'. Put a WHILE loop inside 'run()' to control the movement of 'glider'. You can use the '.getY()' method to determine the Y-coordinate of 'glider' and use it to stop the loop. In other words, when the Y-coordinate reaches a certain value, you can exit the loop.
You can use either the '.move()' method or the '.moveTo()' method to control the movement of 'glider'. 'move(dx, dy)' causes the object's X-coordinate to change by 'dx' and its Y-coordinate to change by 'dy'. 'moveTo(x, y)' causes the object to move to the point (x, y). Come up with a way of moving the glider.
A more complex possibility that you can then try is:
angle = i/150.0;
x = 350+100*Math.cos(angle);
y = 5+100*Math.sin(angle)+0.00005*i*i;
where 'i' is an integer that gets incremented inside the loop.
You will also want to include the 'pause()' command to slow down the animation. For example:
where 'TIME_DELAY' is an integer that specifies how many milliseconds to pause.
Here is a screen shot of my applet after it starts but before 'Click To Fly' has been clicked:
You can download Animation.zip to use as a starting point in writing your program. This zip file includes Animation.java and two JPEG files, esb.jpg and hangGlider.jpg. You can use other image files than these if you want to.