Question
public static final int WINDOW_MAXWIDTH = 800; public static final int WINDOW_MAXHEIGHT = 650; public static Scanner kb = new Scanner(System.in); public static int speed
public static final int WINDOW_MAXWIDTH = 800; public static final int WINDOW_MAXHEIGHT = 650; public static Scanner kb = new Scanner(System.in); public static int speed = 1;
speed method to be used is called changeSpeed()
My question is how to write a methods called public static void moveToCenterMakeLargeShrinkChangeColor(Circles ball) --- that puts the ball in the center of the canvas so that it takes up the canvas and then decreases the size of the ball until the diameter reaches 50. It should change colors between blue and red every 25 pixels. The ball should stay in the center of the canvas.
Below is the complete Cirlces Class.
import java.awt.*; import java.awt.geom.*; /** * A circle that can be manipulated and that draws itself on a canvas. * * @author Michael Klling and David J. Barnes * @version 2016.02.29 */ public class Circles { private int diameter; private int xPosition; private int yPosition; private String color; private boolean isVisible; public Circles() { diameter = 40; xPosition = 250; yPosition = 200; color = "blue"; isVisible = false; } public Circles(int diameter, int xPosition, int yPosition, String color) { this.diameter = diameter; this.xPosition = xPosition; this.yPosition = yPosition; this.color = color; isVisible = false; } public void makeVisible() { isVisible = true; draw(); } public void makeInvisible() { erase(); isVisible = false; } public boolean isVisible() { return isVisible; } public void setColor(String color) { this.color = color; draw(); } public void setXPosition(int value) { xPosition = value; draw(); } public void setYPosition(int value) { yPosition = value; draw(); } public void changeDiameter(int value) { diameter = value; draw(); } public String getColor() { return color; } public int getXPosition() { return xPosition; } public int getYPosition() { return yPosition; } public int getDiameter() { return diameter; } public void moveTo(int x, int y) { xPosition = x; yPosition = y; draw(); } /** * Draw the circle with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, diameter, diameter)); canvas.wait(10); } } /** * Erase the circle on screen. */ private void erase() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.erase(this); } } }
import java.awt.*; import java.awt.geom.*; /** * A circle that can be manipulated and that draws itself on a canvas. * * @author Michael Klling and David J. Barnes * @version 2016.02.29 */ public class Circles { private int diameter; private int xPosition; private int yPosition; private String color; private boolean isVisible; public Circles() { diameter = 40; xPosition = 250; yPosition = 200; color = "blue"; isVisible = false; } public Circles(int diameter, int xPosition, int yPosition, String color) { this.diameter = diameter; this.xPosition = xPosition; this.yPosition = yPosition; this.color = color; isVisible = false; } public void makeVisible() { isVisible = true; draw(); } public void makeInvisible() { erase(); isVisible = false; } public boolean isVisible() { return isVisible; } public void setColor(String color) { this.color = color; draw(); } public void setXPosition(int value) { xPosition = value; draw(); } public void setYPosition(int value) { yPosition = value; draw(); } public void changeDiameter(int value) { diameter = value; draw(); } public String getColor() { return color; } public int getXPosition() { return xPosition; } public int getYPosition() { return yPosition; } public int getDiameter() { return diameter; } public void moveTo(int x, int y) { xPosition = x; yPosition = y; draw(); } /** * Draw the circle with current specifications on screen. */ private void draw() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.draw(this, color, new Ellipse2D.Double(xPosition, yPosition, diameter, diameter)); canvas.wait(10); } } /** * Erase the circle on screen. */ private void erase() { if(isVisible) { Canvas canvas = Canvas.getCanvas(); canvas.erase(this); } }
Canvas Class below
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Klling (mik) * * @version 2016.02.29 */ public class Canvas { // Note: The implementation of this class (specifically the handling of // shape identity and colors) is slightly more complex than necessary. This // is done on purpose to keep the interface and instance fields of the // shape objects in this project clean and simple for educational purposes. private static Canvas canvasSingleton; /** * Factory method to get the canvas singleton object. */ public static Canvas getCanvas() { if(canvasSingleton == null) { canvasSingleton = new Canvas("Assignment 2 Spring 2018", 800, 650, Color.white); } canvasSingleton.setVisible(true); return canvasSingleton; } // ----- instance part ----- private JFrame frame; private CanvasPane canvas; private Graphics2D graphic; private Color backgroundColor; private Image canvasImage; private List
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started