// Aaron Tan
// BallV2GUI class:
//   Data members: colour, radius, x- and y-coord of centre,
//                 isVisible
// 
// Version 2: Added the x- and y-coordinate of the centre.
// GUI version: Added isVisible.

import java.awt.*;
import java.awt.geom.*;

class BallV2GUI {

   /************** Data members **********************/

   fill in the code

   /************** Constructor **********************/
   // only one constructor is created as overloading
   // is introduced later in Chapter 7
   // Default constructor creates a yellow, radius 10.0,
   // centre at (20,20) object
   public BallV2GUI (){
      fill in the code
   }

   /**************** Accessors ***********************/

   fill in the accessors

   /**************** Mutators ************************/

   fill in the mutators

   /***************** Other methods ******************/

   // Move this ball dist pixels vertically
   public void moveVertical(int dist) {
      fill in the code
      
      draw();
   }

   // Move this ball dist pixels horizontally
   public void moveHorizontal(int dist) {
      fill in the code
 
      draw();
   }
   
   // Slowly move this ball dist pixels vertically
   // Students are supposed to fill in this method
   public void slowMoveVertical(int dist) {
      fill in the code
   }
   
   // Slowly move this ball dist pixels horizontally 
   // Students are supposed to fill in this method
   public void slowMoveHorizontal(int dist) {
      fill in the code
   }
   
   // Make this ball visible. If it was already visible, do nothing.
   public void makeVisible() {
      setVisible(true);
      draw();
   }
   
   // Make this ball invisible. If it was already invisible, do nothing.
   public void makeInvisible() {
      erase();
      setVisible(false);
   }
   
   // Change the size of ball
   public void changeSize(double newRadius) {
      erase();
      setRadius(newRadius);
      draw();
   }
   
   // Change the colour
   // Valid colours are "red", "yellow", "blue", "green", "magenta" and "black".
   public void changeColour(String newColour) {
      setColour(newColour);
      draw();
   }
   
   // Draw the ball with current specification on screen
   private void draw() {
     if (isVisible) {
        Canvas canvas = Canvas.getCanvas();
        
        // Ellipse2D's constructor's first two parameters are the x- and y-coordinates
        // of the ellipse's top-left corner, and the next two parameters are the diameters
        // of the ellipse in the x- and y-axes respectively
        canvas.draw(this, getColour(), new Ellipse2D.Double(getXCoord()-getRadius(), 
                    getYCoord()-getRadius(), getRadius()*2, getRadius()*2)); 
        canvas.wait(10);               
     }
   }

   // Erase the ball on screen
   private void erase() {
      if (isVisible) {
         Canvas canvas = Canvas.getCanvas();
         canvas.erase(this);
      }
   }
}

