Question

In: Computer Science

Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result...

Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result and create 3 textfileds. Create sum button. You have to enter number1 and number2 in the textfileds. If you click the button Sum, the result will be showed in the third text field.

Solutions

Expert Solution

package practice;  
/* -> Simple calculation: Addition of two numbers using javafx in eclipse
-> Save file name as Calculation.java*/
import javafx.application.Application; 
import javafx.event.ActionEvent;  
import javafx.event.EventHandler;   
import javafx.scene.Scene;  
import javafx.scene.control.Button;  
import javafx.scene.control.Label;  
import javafx.scene.control.TextField;  
import javafx.scene.layout.GridPane;  
import javafx.stage.Stage;
public class Main extends Application {
        
@Override  
public void start(Stage primaryStage) throws Exception {  
        // TODO Auto-generated method stub  
        Label number1=new Label("Number 1 :");  //Label 1
        Label number2 = new Label("Number 2 :"); //Label 2
        Label result = new Label("Result :"); //Label 3 
        TextField num1=new TextField();  //text field 1
        TextField num2=new TextField(); //text field 2
        TextField res=new TextField(); //text field 3
        Button sumButton = new Button("Sum");
        //Add event listener to sumButton
        sumButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
                Double d1=Double.parseDouble(num1.getText()); //getting the entered in nuber1 textfield and changed to double
                Double d2=Double.parseDouble(num2.getText());//getting the entered in nuber2 textfield and changed to double
                res.setText(Double.toString(d1+d2)); //set the text to the result textfiled as adddition of two numbers
        }
        }); 
        /* Adding all Ui elements to root */
        GridPane root = new GridPane();  
        root.addRow(0, number1, num1);  
        root.addRow(1, number2, num2);
        root.addRow(2, result, res); 
        root.addRow(3, sumButton);  
        //Scene creation
        Scene scene=new Scene(root,500,300);  
        primaryStage.setScene(scene);  
        primaryStage.setTitle("Simple Calculation");  
        primaryStage.show();  
}
/* Main Method */
public static void main(String[] args) {  
        launch(args);     
}

}  

Related Solutions

NASM - Create a program that adds two binary numbers and returns the result in binary.
NASM - Create a program that adds two binary numbers and returns the result in binary.
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
Write a JavaScript program with a function named fives that reads two numbers from two text...
Write a JavaScript program with a function named fives that reads two numbers from two text fields and then outputs to a div "True" if both of the numbers are greater than 5 or if their sum is greater than 20. Otherwise your function should output "False" to the div. If you wish, you may use the following HTML code to begin your program.
Write a JavaFx program to create Forms as front end and JDBC as back end to...
Write a JavaFx program to create Forms as front end and JDBC as back end to store the data and retrieve the data.
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
The following program is written to calculate the addition for two numbers (9,3).  Unfortunately, the program has...
The following program is written to calculate the addition for two numbers (9,3).  Unfortunately, the program has Compile-time and Run-time errors that prevent the program from running and producing the correct result. Using the Table 2.1 below, allocate the error(s) on each program line. // define new class publicCalculation { privateintresult_add // define add method to add two numbers publicvoidadd(intfirst_number,intsecond_number) { int   number1= first_number; doublenumber2= second_number; result_add= number1/number2; } / return the value publicintgetvalue() { returnresult_add; } publicstaticvoidmain(String[] args) { // define...
Write a program in python language, which accepts 2 numbers and a + sign (for addition)...
Write a program in python language, which accepts 2 numbers and a + sign (for addition) A sign - (for subtraction) A sign * (for multiplication), / (for division) Then calculate and to display the result of the operation he chose with the two numbers. Displaying the appropriate message
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Create a program that ask to input two users and the result will vary on their...
Create a program that ask to input two users and the result will vary on their name with similar digits. In a game of F.L.A.M.E.S , it will count and repeat depends on their name that has a similar digit. For an Example (JOE RIZAL) and (JACKLYN BRACKEN) - JOE RIZAL has - 5 similar digits , while JACKLYN BRACKEN has 6 similar digits so a total of 11. F - Friends - 1,7 L - Lover - 2,8 A...
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT