Question: Create a GUI on java that looks like Including this in the project import javafx.collections.ObservableList; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Polygon; public class UpdateablePolygon extends

Create a GUI on java that looks like
Including this in the project
import javafx.collections.ObservableList;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
public class UpdateablePolygon extends StackPane {
private int sides;
private double radius;
public int getSides(){
return this.sides;
}
public double getRadius(){
return this.radius;
}
public UpdateablePolygon(){
//this.setPrefSize(125,125);
this.radius =100;
this.paint();
//this.setStyle("-fx-border-color: black");
}
public void setSides(int sides){
if (sides >2){
this.sides = sides;
this.paint();
}
}
private void paint(){
this.getChildren().clear();
double centerX = this.getWidth()/2;
double centerY = this.getHeight()/2;
Polygon poly = new Polygon();
poly.setFill(Color.WHITE);
poly.setStroke(Color.BLACK);
ObservableList list = poly.getPoints();
// Add points to the polygon list
for (int i =0; i this.sides; i++){
list.add(centerX + this.radius * Math.cos(2* i * Math.PI / this.sides));
list.add(centerY - this.radius * Math.sin(2* i * Math.PI / this.sides));
}
this.getChildren().add(poly);
}
}
 Create a GUI on java that looks like Including this in

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!