- import objectdraw.*;
- import java.awt.*;
- // A program that produces an animation of the sun rising and setting.
- // The animation is driven by dragging the mouse.
- public class ScrollingSun extends WindowController {
- private FilledOval sun; // Circle that represents the sun
- // Place the sun and some brief instructions on the screen
- public void begin() {
- sun = new FilledOval( 50, 150, 100, 100, canvas);
- new Text( "Drag the mouse up or down", 20, 30, canvas );
- }
- // Move the sun to follow the mouse's vertical motion
- public void onMouseDrag( Location mousePosition ) {
- sun.moveTo( 50, mousePosition.getY() );
- }
- }
Raw Paste