JAVA   49
ScrollingSun1
Guest on 9th February 2023 03:07:47 AM


  1. import objectdraw.*;
  2. import java.awt.*;
  3.  
  4.     // A program that produces an animation of the sun rising and setting.
  5.     // The animation is driven by dragging the mouse.
  6. public class ScrollingSun extends WindowController {
  7.  
  8.     private FilledOval sun;  // Circle that represents the sun
  9.  
  10.         // Place the sun and some brief instructions on the screen
  11.     public void begin() {
  12.         sun = new FilledOval( 50, 150, 100, 100, canvas);
  13.         new Text( "Drag the mouse up or down", 20, 30, canvas );
  14.     }
  15.  
  16.         // Move the sun to follow the mouse's vertical motion
  17.     public void onMouseDrag( Location mousePosition ) {
  18.         sun.moveTo( 50, mousePosition.getY() );
  19.     }
  20.  
  21. }

Raw Paste

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