- import objectdraw.*;
- import java.awt.*;
- // A program that produces an animation of the sun rising.
- // The animation is driven by clicking the mouse button.
- // The faster the mouse is clicked, the faster the sun will rise.
- public class RisingSun extends WindowController{
- private FilledOval sun; // Circle that represents the sun
- private Text instructions; // Display of instructions
- // Place the sun and some brief instructions on the screen
- public void begin() {
- sun = new FilledOval( 50, 150, 100, 100, canvas);
- instructions = new Text( "Please click the mouse repeatedly", 20, 20, canvas);
- }
- // Move the sun up a bit each time the mouse is clicked
- public void onMouseClick(Location point) {
- sun.move(0, -5);
- instructions.hide();
- }
- // Move the sun back to its starting position and redisplay
- // the instructions
- public void onMouseExit(Location point){
- sun.moveTo( 50, 150 );
- instructions.show();
- }
- }
Raw Paste