Question: Modify the following Polygon GUI App in java to have the program change the shape of the polygon depending on the dimensions, for example, it

Modify the following Polygon GUI App in java to have the program change the shape of the polygon depending on the dimensions, for example, it should display a circle when sides and radius are 100.package silvestri;
import java.awt.Color;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import shapes.RegularPolygon;
import shapes.Circle;
import shapes.Rectangle;
import shapes.Shape;
import shapes.Triangle;
import silvestri.UpdateablePolygon;
public class PolygonApp extends Application {
private TextField sidesField;
private TextField radiusField;
private TextField areaField;
private TextField perimeterField;
private UpdateablePolygon polygon;
@Override
public void start(Stage primaryStage){
// Create input fields and labels
Label sidesLabel = new Label("Sides:");
Label radiusLabel = new Label("Radius:");
sidesField = createClearableTextField();
radiusField = createClearableTextField();
Label areaLabel = new Label("Area:");
Label perimeterLabel = new Label("Perimeter:");
areaField = createReadonlyTextField();
perimeterField = createReadonlyTextField();
// Create a button
Button calculateButton = new Button("Calculate");
calculateButton.setOnAction(event -> calculatePolygon());
// Create an HBox for input fields and button
HBox inputBox = new HBox(10);
inputBox.getChildren().addAll(sidesLabel, sidesField, radiusLabel, radiusField, calculateButton);
// Create a BorderPane to hold input fields, output fields, and the polygon
BorderPane root = new BorderPane();
root.setTop(inputBox);
root.setLeft(areaLabel);
root.setLeft(areaField);
root.setRight(perimeterLabel);
root.setRight(perimeterField);
polygon = new UpdateablePolygon();
polygon.setSides(6);
root.setCenter(polygon);
// Configure the scene and stage
Scene scene = new Scene(root,600,400);
primaryStage.setTitle("Polygon Statistics Solver - Tony Silvestri");
primaryStage.setScene(scene);
primaryStage.show();
// Set the initial polygon sides and radius
sidesField.setText("6");
radiusField.setText("100");
calculatePolygon();
}
private TextField createClearableTextField(){
TextField textField = new TextField();
textField.setPrefWidth(100);
textField.setOnMousePressed(event -> textField.clear());
return textField;
}
private TextField createReadonlyTextField(){
TextField textField = new TextField();
textField.setPrefWidth(100);
textField.setEditable(false);
textField.setFocusTraversable(false);
textField.setMouseTransparent(true);
return textField;
}
private void calculatePolygon(){
int sides = Integer.parseInt(sidesField.getText());
double circumRadius = Double.parseDouble(radiusField.getText());
RegularPolygon regularPolygon = new RegularPolygon(sides, circumRadius, "Black", false);
areaField.setText(String.format("%.2f", regularPolygon.getArea()));
perimeterField.setText(String.format("%.2f", regularPolygon.getPerimeter()));
}
public static void main(String[] args){
launch(args);
}
}Develop a GUI that looks exactly like the following:
Polygon Statistics Solver - Tony Silvestri
Sides
Area
Perimeter
To create the polygon in the GUI, include the attached UpdateablePolygon.java file into your project. Put the file in a
package called silvestri.
Add the classes you used in the first part of this assignment and put them into a shapes package. (The test file source
files need not be included.)
When the calculate button is clicked, have your gui use your RegularPolygon class to determine the area and perimeter
from the specified sides and radius textfields. Also use the methods provided by the UpdateablePolygon to draw a cool
polygon.
 Modify the following Polygon GUI App in java to have the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!