Problem Description Draw a circle with three random points on the circle. Connect the points to form a triangle. Display the angles in the triangle. Use the mouse to drag a point along the perimeter...

1 answer below »


Problem Description


Draw a circle with three random points on the circle. Connect the points to form a triangle. Display the angles in the triangle. Use the mouse to drag a point along the perimeter of the circle. As you drag it, the triangle and angles are redisplayed dynamically as shown in Figure 1.


You will need to create a DrawTriangle class (not main class) which takes some appropriate parameters in one of its methods to draw the triangle within the circle as shown in Figure 1. Your will not get full marks if DrawTriangle class is not created nor used as it as part of Object-Oriented Software Development.





Figure

1
: Sample output


Here is the formula to compute angles:




Note, acos(x) is cos-1(x)










What to submit:


Submit the 5 screenshots of the output along with a check list of the following steps using this word document and full
NetBeans Project folder. Note, your project should be developed using NetBeans otherwise your work will not be marked. Copy and paste your code into this word document too.


Put this word document in your NetBeans project folder and then zip before submission.




Your code:




  1. Can your program display a circle in the centre of the frame, if not, why?



Write your answer here:





  1. Can your program display three points on the circle, if not, why?



Write your answer here:





  1. Can your program draw a triangle using these three points, if not, why?



Write your answer here:





  1. Can your program compute the angles in the triangle, if not, why?



Write your answer here:





  1. Can your program display the angles in the triangle, if not, why?



Write your answer here:





  1. Note that three points are three small circles. Can your program detect which small circle is pressed by the mouse, if not, why?



Write your answer here:





  1. Can your program drag a small circle that has been pressed, if not, why?



Write your answer here:





  1. Can your program drag a small circle along the perimeter of the circle, if not, why? (Hint: Ignore the mouse drag if it is not along the perimeter of the circle.)



Write your answer here:


Answered 1 days AfterFeb 06, 2021

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
142 Votes
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...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here