Question

In: Computer Science

In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius....

In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea.

Please write the portions of codes which calculates the circle’s area and the square's area when the button(btCalculate) is clicked and both of the calculated areas are displayed on their respective textarea controls(trCircleArea, trSquareArea).   Assuming the codes for layout setup are completed and you are only required to complete the calculation part and handling of button click event.

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

//adding action listener to the button using a lambda expression
btCalculate.setOnAction(e -> {
    //parsing circle's radius from tfRadius text field
    double radius = Double.parseDouble(tfRadius.getText());
    //finding circle's area
    double circ_area = Math.PI * radius * radius;
    //displaying it in trCircleArea
    trCircleArea.setText(Double.toString(circ_area));
    //finding square's diagonal (diameter of circle)
    double sq_diagonal = radius * 2;
    //finding square's area using diagonal, which is half of d^2
    //you can check online to know how you get this formula.
    double sq_area = sq_diagonal * sq_diagonal * 0.5;
    //displaying square's area in trSquareArea
    trSquareArea.setText(Double.toString(sq_area));
});

/*NOTE ON FINDING AREA OF SQUARE USING DIAGONAL*/

A diagonal cuts the square into two right triangles, so

diagonal square = sum of squares of other two sides (Pythagoras theorem)

Square has same width and height, so the formula becomes

diagonal square = 2 * (square of side)

here, square of side is the formula to find the area of square, hence

diagonal square = 2 * area

and finally

area = (diagonal square)/2 or (diagonal square)*0.5

Related Solutions

In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius....
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write portions of codes which calculates the circle's area and the square's...
Java In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s...
Java In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write the portions of codes which calculates the circle’s area and...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters...
Design JavaFX application with 7 labels and one textfield where user enters input inches.  When user enters his choice and presses enter key to complete input, program outputs resulting yards, feet, and inches.   Use class P5 that extends Application  with start method in it, and class P5Pane that extend GridPane. The only inctance variables for P5Pane class are inputInches where user enters input  inches, and three labels: outYards, outFeet, and outInches where program displays result of conversion.  Use the following names for instance variables:...
JAVAFX Create a JavaFx application that is an MP3 player. The size of the media player...
JAVAFX Create a JavaFx application that is an MP3 player. The size of the media player should be 800 pixels in width and 650 pixels in height. The media player should have a TextField that allows the user to type the full path of the .mp3 file to be played. The application should also use 2 Checkbox controls to show/hide the total playing time and the status (methods of MediaPlayer class). Use 2 RadioButton controls to change background colors (red...
This lab is designed to design an event driven animation application which JavaFX application implementing a...
This lab is designed to design an event driven animation application which JavaFX application implementing a racing car image. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process. Let the user pause/resume the animation with a button press/release and increase/decrease the car speed by pressing the up and down arrow keys. The car used for this application has the following attributes. Task(s) Task 1: Create a...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
Create a JavaFX application that lets the user enter the food charge for a meal at...
Create a JavaFX application that lets the user enter the food charge for a meal at a restaurant. For example, if $20 is entered as a food charge for a meal then $3.6 should be displayed for the tip, $1.4 should be displayed for sales tax, and $25 should be displayed as a total of all three amounts. Modification 1: create a text box (not a pop up) for the user to enter a percent tip (don't just hardcode it...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT