-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathController.java
More file actions
36 lines (32 loc) · 942 Bytes
/
Controller.java
File metadata and controls
36 lines (32 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package sample;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
public class Controller {
@FXML
private Label myLabel;
@FXML
private TextField myTextField;
@FXML
private TextField myTextField2;
@FXML
private Button myButton;
int firstNumber;
int secondNumber;
public void submit(ActionEvent event) {
try {
firstNumber = Integer.parseInt(myTextField.getText());
secondNumber = Integer.parseInt(myTextField2.getText());
int sum=firstNumber+secondNumber;
myLabel.setText("Your answer is "+sum);
}
catch(NumberFormatException e){
myLabel.setText("Enter number.");
}
catch(Exception e){
myLabel.setText("Error");
}
}
}