Answered Essay: Create, test, and document a Java program with the following classes. Figure: This is an abstract class Rectangle: This extends Figure an

this should be done by javafx noting else.

Create, test, and document a Java program with the following classes. Figure: This is an abstract class Rectangle: This extends Figure and implements the functionality needed to draw Circle: This extends Figure and implements the functionality needed to draw filled The GUI should appear as below. (Minor deviations are fine.) filled rectangles with a given color. circles with a given color. Assignment 2 Circle [x-19, y-59, radius-76, color BLUE] Rectangle [x=199, y=124, width=66, height-57, color=GREEN Circle [x=71, y=111, radius-26, color=RED] Rectangle [x-110, y 191, width-64, height-48, color-GREEN] Circle [x-30, y-199, radius-37, color-GREEN] Rectangle [x=71, y=323, width-94, height-13, color=BLUE] Rectangle [x=89, y=19, width=74, height=43, color=RED] Rectangle [x=197, y=257, width-35, height-38, color-RED] Red Green Blue Rectangle Circle Exit 27-Aug-2017 The program should work as shown in the video file and demonstrated in class. As in the video file, to draw the rectangle, the user first clicks the top left corner and then the bottom right corner. To draw a circle, the user clicks the center and

Create, test, and document a Java program with the following classes. Figure: This is an abstract class Rectangle: This extends Figure and implements the functionality needed to draw Circle: This extends Figure and implements the functionality needed to draw filled The GUI should appear as below. (Minor deviations are fine.) filled rectangles with a given color. circles with a given color. Assignment 2 Circle [x-19, y-59, radius-76, color BLUE] Rectangle [x=199, y=124, width=66, height-57, color=GREEN Circle [x=71, y=111, radius-26, color=RED] Rectangle [x-110, y 191, width-64, height-48, color-GREEN] Circle [x-30, y-199, radius-37, color-GREEN] Rectangle [x=71, y=323, width-94, height-13, color=BLUE] Rectangle [x=89, y=19, width=74, height=43, color=RED] Rectangle [x=197, y=257, width-35, height-38, color-RED] Red Green Blue Rectangle Circle Exit 27-Aug-2017 The program should work as shown in the video file and demonstrated in class. As in the video file, to draw the rectangle, the user first clicks the top left corner and then the bottom right corner. To draw a circle, the user clicks the center and

Expert Answer

 

GUI.java

import java.awt.Stroke;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.control.Labeled;
import javafx.scene.control.ToggleButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;

// 3 points
public class GUI extends Application {
public final static int SQUARE = 0;
public final static int CIRCLE = 1;
public final static int RECTANGLE = 2;
private Color color; // used to keep the last selected color
private Label label; // used to display information on GUI

// 0.2 point
// update the text of the label object
public void setText(String str) {
// ################ COMPLETE ################
label.setText(str);
}

@Override
public void start(Stage primaryStage) {
HBox mainPane = new HBox();

//occur leftPane and rightPane
VBox leftPane = new VBox(10);
FigureCanvas rightPane = new FigureCanvas(10, 400, 500, this);
label = new Label();
label.setWrapText(true);

//occur Circle button
Button btnCircle = new Button(“Circle”);
btnCircle.setMinSize(80, 20);

//occur Square button
Button btnSquare = new Button(“Square”);
btnSquare.setMinSize(80, 20);

//occur Rectangle button
Button btnRectangle = new Button(“Rectangle”);
btnRectangle.setMinSize(80, 20);

//occur Clear All button
Button btnClearAll = new Button(“Clear All”);
btnClearAll.setMinSize(80, 20);

//occur Color ToggleGroup
ToggleGroup colorGroup = new ToggleGroup();

//occur Red radio button and set ToggleGroup
RadioButton radioRed = new RadioButton(“Red”);
radioRed.setToggleGroup(colorGroup);

//occur Green radio button and set ToggleGroup
RadioButton radioGreen = new RadioButton(“Green”);
radioGreen.setToggleGroup(colorGroup);

//occur Blue radio button and set ToggleGroup
RadioButton radioBlue = new RadioButton(“Blue”);
radioBlue.setToggleGroup(colorGroup);

//occur label1 and label2 on the leftPane
Label lblInfo1 = new Label();
Label lblInfo2 = new Label();

//Buttons,labels and RadioButtons add on the leftPane
leftPane.getChildren().addAll(radioRed, radioGreen, radioBlue);
leftPane.getChildren().addAll(btnCircle, btnSquare, btnRectangle, btnClearAll);
leftPane.getChildren().addAll(lblInfo1, lblInfo2,label);

//occur leftPane width
leftPane.setMinWidth(100);

//occur leftPane border right, left, down, up
leftPane.setPadding(new Insets(10, 0, 10, 10));

//occur rightPane width
rightPane.setWidth(400);

//occur rightPane border and color
rightPane.setStyle(“-fx-border-color: #2e8b57; -fx-border-width: 1px; “);

//leftPane and rightPane add on the mainPane
mainPane.getChildren().add(leftPane);
mainPane.getChildren().add(rightPane);

Scene scene = new Scene(mainPane, 500, 500);
primaryStage.setTitle(“Draw Figure”);
primaryStage.setScene(scene);
primaryStage.show();

radioRed.setOnAction(e -> {
if (radioRed.isSelected()) {
color = Color.RED;
}
});

radioGreen.setOnAction(e -> {
if (radioGreen.isSelected()) {
color = Color.GREEN;
}
});

radioBlue.setOnAction((ActionEvent e) -> {
if (radioBlue.isSelected()) {
color = Color.BLUE;
}
});

btnCircle.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
rightPane.addFigure(CIRCLE, color);
}
});

btnRectangle.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
rightPane.addFigure(RECTANGLE, color);
}
});

btnSquare.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
rightPane.addFigure(SQUARE, color);
}
});

btnClearAll.setOnMouseClicked(new EventHandler<MouseEvent>() {
public void handle(MouseEvent me) {
rightPane.removeAll();
}
});
}

public static void main(String[] args) {
launch(args);
}
}

Figure.java

import hw2.Drawable;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

// 1 point
abstract class Figure implements Drawable, Comparable<Figure> {
// (“x”, “y”) are coordinates of the “center” of the figure.
// “counter” helps counting the number of figures.
// Each figure has a unique “id” which can be determined through counter.
protected int id;
protected double x;
protected double y;
protected Color color;
private static int counter;

// 0.2 point
// initialization
public Figure(double x, double y, Color c) {
// ################ COMPLETE ################
this.x = x;
this.y = y;
this.color = c;
counter++;
}

// 0.2 point
// set counter to zero
public static void setCounterToZero() {
// ################ COMPLETE ################
counter=0;
}

// 0.4 point
// Compares this figure with the specified figure, based on their area
public int compareTo(Figure fig) {
// ################ COMPLETE ################
if(this.getArea()< fig.getArea()){
return -1;
}else if(this.getArea()>fig.getArea()){
return 1;
}else
return 0;

}

// 0.2 point
// returns string representation of this figure that
// contains id, x and y information
public String toString() {
// ################ COMPLETE ################
return (“nID: “+this.id +”nX: “+ this.x +”nY: “+ this.y);

}

// draw this figure through GraphicsContext object given as argument.
// setStroke, strokeOval and strokeRect methods of GraphicsContext may be useful.
public abstract void draw(GraphicsContext gc);

// returns true if (x, y) are coordinates inside the figure, false otherwise
public abstract boolean isInside(double x, double y);

// returns the area of this figure
public abstract double getArea();

}

Circle.java

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

// 1 point
public class Circle extends Figure {

private double radius;

// 0.2 point
// initialization
public Circle(double x, double y, double radius, Color c) {
// ################ COMPLETE ################
super(x,y,c);
super.x = x;
super.y = y;
super.color = c;
this.radius = radius;
}

// 0.2 point
// returns the area of this figure
public double getArea() {
// ################ COMPLETE ################
return Math.PI * radius * radius;
}

// 0.2 point
// draw this figure through GraphicsContext object given as argument
public void draw(GraphicsContext gc) {
// ################ COMPLETE ################
gc.getStroke();
gc.setStroke(color);
gc.strokeOval(x, y, radius, radius);
}

// 0.2 point
// returns true if (x, y) are coordinates inside the figure, false otherwise
public boolean isInside(double x, double y) {
// ################ COMPLETE ################
double x1 = this.x;
double x2 = this.x + 2*(this.radius);
double y1 = this.y;
double y2 = this.y + 2*(this.radius);
if(x >= x1 && x <= x2 && y >= y1 && y <= y2){
return true;
}
return false;
}

// 0.2 point
// returns string representation of this figure that contains figure name, radius,
// and id, x and y information obtained through superclass by a method call
@Override
public String toString() {
// ################ COMPLETE ################
String info = “Name: Circle” + “nRadius: ” + this.radius + ” “;
info += super.toString();
return info;
}
}

Drawable.java

import javafx.scene.canvas.GraphicsContext;

public interface Drawable {
// draw this through GraphicsContext object given as argument
public abstract void draw(GraphicsContext gc);
}

FigureCanvas.java

import hw2.GUI;
import java.util.ArrayList;
import java.util.Random;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

// 3 points
// manages and draws figures
public class FigureCanvas extends Canvas {
private ArrayList<Figure> list; // contains figures
private int capacity; // determines the max number of figures in the list
private GraphicsContext gc; // used for drawing figures
private GUI myGUI; // points to the GUI object
private Figure fig_selected; // lastly selected figure

// 0.4 point
// initialization
public FigureCanvas(int capacity, int width, int height, GUI myGUI) {
// ################ COMPLETE ################
super(width, height);
list = new ArrayList<Figure>();
this.capacity = capacity;
this.myGUI = myGUI;

// getGraphicsContext2D is a method of Canvas returning GraphicsContext object,
// which is used for drawing figures
gc = getGraphicsContext2D();
// draws a rectangle on the border of the canvas
gc.strokeRect(0, 0, width, height);

}

public void addFigure(int figure, Color c) {
// ################ COMPLETE ################
Random rnd = new Random();

if (list.size()==10 || list.size()>10)
myGUI.setText(“CAPACITY FULL!!!”);
else{
if (figure==0) {
Figure fs = new Square(rnd.nextInt(401), rnd.nextInt(501), rnd.nextInt(101), c);

list.add(fs);
fs.draw(gc);
myGUI.setText(fs.toString());
}
else if (figure==1) {
Figure fs = new Circle(rnd.nextInt(400), rnd.nextInt(501), rnd.nextInt(51), c);

list.add(fs);
fs.draw(gc);
myGUI.setText(fs.toString());
}
else{
Figure fs = new Rectangle(rnd.nextInt(400), rnd.nextInt(501), rnd.nextInt(201), rnd.nextInt(251), c);

list.add(fs);
fs.draw(gc);
myGUI.setText(fs.toString());
}
}
}

// 0.6 point
// select the figure containing the given (x, y) coordinates
public void selectFigureContaining(double x, double y) {
String str = “”;
Figure fig_current = null; // points the figure containing the given (x, y) coordinates

if (fig_selected != null && fig_current != null) {
str += fig_selected + “n”;
int res = fig_selected.compareTo(fig_current);
if (res > 0)
str += “>”;
else if (res < 0)
str += “<“;
else
str += “==”;
str += “n” + fig_current;
}
fig_selected = fig_current;

// 0.2 point
// display comparison information on GUI through setText method call
// ################ COMPLETE ################
myGUI.setText(str);
myGUI.toString();

}

public void removeAll() {
// ################ COMPLETE ################
list.clear();
gc.clearRect(1, 1, 398, 498);
myGUI.setText(“Cleaned !”);

}
}

Rectangle.java

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

// 1 point
public class Rectangle extends Square {
// in addition to the “width” data field of a square,
// “height” data field is added for a rectangle.
private double height;

public Rectangle(double x, double y, double width, double height, Color c) {
// ################ COMPLETE ################
super(x,y,width,c);
this.height = height;
super.width = width;
super.x = x;
super.y = y;
}

// 0.2 point
// returns the area of this figure
public double getArea() {
// ################ COMPLETE ################
return width*height;
}

// 0.2 point
// draw this figure through GraphicsContext object given as argument
public void draw(GraphicsContext gc) {
// ################ COMPLETE ################
gc.getStroke();
gc.setStroke(color);
gc.strokeRect(x, y, width, height);
}

// 0.2 point
// returns true if (x, y) are coordinates inside the figure, false otherwise
public boolean isInside(double x, double y) {
// ################ COMPLETE ################
double figurex1 = this.x;
double figurex2 = this.x + this.width;
double figurey1 = this.y;
double figurey2 = this.y + this.height;
if(x >= figurex1 && x <= figurex2 && y >= figurey1 && y <= figurey2){
return true;
}
return false;
}

// 0.2 point
// returns string representation of this figure that contains figure name, width,
// height and id, x and y information
public String toString() {
// ################ COMPLETE ################
String info = “Name: Rectangle ” + “nHeight :” + this.height + ” “;
info += “nWidth: ” + this.width + “nID: ” + this.id + “nX: ” + this.x + “nY: ” + this.y;
return info;

}
}

Square.java

import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;

// 1 point
public class Square extends Figure {

// since both sides of a square are equal,
// a “width” data field is enough to store the necessary data concerning a square
protected double width;

// 0.2 point
// initialization
public Square(double x, double y, double width, Color c) {
// ################ COMPLETE ################
super(x,y,c);
super.x = x;
super.y = y;
this.width = width;
super.color = c;
}

// 0.2 point
// returns the area of this figure
public double getArea() {
// ################ COMPLETE ################
return width*width;
}

// 0.2 point
// draw this figure through GraphicsContext object given as argument
public void draw(GraphicsContext gc) {
// ################ COMPLETE ################
gc.getStroke();
gc.setStroke(color);
gc.strokeRect(x, y, width, width);
}

// 0.2 point
// returns true if (x, y) are coordinates inside the figure, false otherwise
public boolean isInside(double x, double y) {
// ################ COMPLETE ################
double figurex1 = this.x;
double figurex2 = this.x + this.width;
double figurey1 = this.y;
double figurey2 = this.y + this.width;
if(x >= figurex1 && x <= figurex2 && y >= figurey1 && y <= figurey2){
return true;
}
return false;
}

public String toString() {
// ################ COMPLETE ################
String info = “Name: Square ” + “nWidth: ” + this.width + ” ” + super.toString();
return info;
}
}

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.