-
Notifications
You must be signed in to change notification settings - Fork 0
/
StringApp.java
91 lines (76 loc) · 2.31 KB
/
StringApp.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package module3.gui.stringapp;
import javafx.application.*;
import javafx.event.*;
import javafx.geometry.Insets;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
/* Foreword: It is worth noting that while this lab is meant to involve
* String parsing and
*/
public class StringApp extends Application {
// Set the Scene
// Create Nodes
TextField inputOne;
TextField inputTwo;
Label labelPlus = new Label("+");
Button equalsButton = new Button("=");
Label labelOutput = new Label("Loading...");
@Override
public void start(Stage stage) {
Pane root = new HBox(10);
Scene myScene = new Scene(root, 400, 200);
root.paddingProperty().set(new Insets(10));
stage.setTitle("Basic Sum Application");
// Set widths for input fields
inputOne = new TextField();
inputOne.setPrefWidth(100);
inputTwo = new TextField();
inputTwo.setEditable(true);
inputTwo.setPrefWidth(100);
labelOutput.setPrefWidth(100);
//
equalsButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
submit();
}
});
stage.setScene(myScene);
root.getChildren().addAll(
inputOne,
labelPlus,
inputTwo,
equalsButton,
labelOutput
);
submit();
stage.show();
}
public double getInputOne() {
try {
return Double.parseDouble(inputOne.getText());
} catch (NumberFormatException e) {
inputOne.setText("" + 0);
return 0;
}
}
public double getInputTwo() {
try {
return Double.parseDouble(inputTwo.getText());
} catch (NumberFormatException e) {
inputTwo.setText("" + 0);
return 0;
}
}
public void submit() {
// I am a god among men. I am a god among men!!!!
// I am a god among men. I am a god among men!!!!
// I am a god among men. I am a god among men!!!!
double sum = getInputOne() + getInputTwo();
labelOutput.setText("" + sum);
}
public static void main(String[] args) {
launch(args);
}
}