Answer To: Problem Description Draw a circle with three random points on the circle. Connect the points to form...
Swapnil answered on Feb 07 2021
75451/Code/Solution.java
75451/Code/Solution.java
import java.awt.Point;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.input.MouseDragEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class TriangleOnCircle extends Application
{
//defining all required UI components
private Circle circle; //big circle
private Circle point1, point2, point3;//points
private Line line1, line2, line3; //lines to connect points
private Text angle1Txt, angle2Txt, angle3Txt; //to display angles between points
@Override
public void start(Stage primaryStage)
{
//creating a circle with radius 150
circle = new Circle(150);
//setting (250,250) as the center of the circle
circle.setCenterX(250);
circle.setCenterY(250);
//no fill color
circle.setFill(Color.TRANSPARENT);
//black outline
circle.setStroke(Color.BLACK);
//initializing three small red circles to represent points
point1 = new Circle(10);
point1.setFill(Color.RED);
point1.setStroke(Color.BLACK);
//adding a mouse dragged listener to point1, to call movePoint method,
//passing the point object and mouse event object
point1.setOnMouseDragged(e -> movePoint(point1, e));
point2 = new Circle(10);
point2.setFill(Color.RED);
point2.setStroke(Color.BLACK);
point2.setOnMouseDragged(e -> movePoint(point2, e));
point3 = new Circle(10);
point3.setFill(Color.RED);
point3.setStroke(Color.BLACK);
point3.setOnMouseDragged(e -> movePoint(point3, e));
//initializing default points and angles
initialize();
//updating the view
update();
//creating a pane and adding everything in order
Pane root = new Pane(circle, line1, line2, line3, angle1Txt, angle2Txt, angle3Txt, point1, point2, point3);
//setting up a scene and displaying it
Scene scene = new Scene(root, 500, 500);
primaryStage.setScene(scene);
primaryStage.setTitle("");
primaryStage.show();
}
//method to initialize every att...