JAVA   50
RisingSun
Guest on 9th February 2023 03:09:09 AM


  1. import objectdraw.*;
  2. import java.awt.*;
  3.  
  4. // A program that produces an animation of the sun rising.
  5. // The animation is driven by clicking the mouse button.
  6. // The faster the mouse is clicked, the faster the sun will rise.
  7. public class RisingSun extends WindowController{
  8.  
  9.     private FilledOval sun;     // Circle that represents the sun
  10.     private Text instructions;  // Display of instructions
  11.  
  12.     // Place the sun and some brief instructions on the screen
  13.     public void begin() {
  14.         sun = new FilledOval( 50, 150, 100, 100, canvas);
  15.         instructions = new Text( "Please click the mouse repeatedly", 20, 20, canvas);
  16.     }
  17.  
  18.     // Move the sun up a bit each time the mouse is clicked
  19.     public void onMouseClick(Location point) {
  20.         sun.move(0, -5);
  21.         instructions.hide();
  22.     }
  23.    
  24.     // Move the sun back to its starting position and redisplay
  25.     // the instructions
  26.     public void onMouseExit(Location point){
  27.         sun.moveTo( 50, 150 );
  28.         instructions.show();
  29.     }
  30. }

Raw Paste

Login or Register to edit or fork this paste. It's free.