- import objectdraw.*;
- import java.awt.*;
- // A program that draws the sky at night.
- // Clicking causes the moon and the cloud to swap positions.
- public class NightSky extends WindowController{
- private FilledOval moon, cloud;
- private FilledRect sky;
- // draws the cloud over top of the moon
- public void begin(){
- sky = new FilledRect( 0, 0, 300, 300, canvas );
- moon = new FilledOval( 50, 50, 100, 100, canvas );
- cloud = new FilledOval( 70, 110, 160, 40, canvas );
- }
- // draws a new scene with the moon over top of the cloud
- public void onMousePress( Location point ){
- canvas.clear();
- sky = new FilledRect( 0, 0, 300, 300, canvas );
- cloud = new FilledOval( 70, 110, 160, 40, canvas );
- moon = new FilledOval( 50, 50, 100, 100, canvas );
- }
- // draws the original scene described in the begin method
- public void onMouseRelease( Location point ){
- canvas.clear();
- begin();
- }
- }
Raw Paste