-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathController.java
More file actions
157 lines (129 loc) · 4 KB
/
Controller.java
File metadata and controls
157 lines (129 loc) · 4 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.StackPane;
import java.util.Random;
import javafx.scene.Parent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.Node;
public class Controller
{
// Anzeige der erreichten Punkte
@FXML
private Label lblPunkte;
@FXML
private Label rechenzeichen;
// Der Button Prüfen oder Weiter
@FXML
private Button button;
// Anzeige der Aufgabe
@FXML
private StackPane inhalt;
// Aufgabe, die gerade angezeigt wird
private Aufgabe a;
// Anzeige, ob die Lösung richtig war
@FXML
private Label lblErgebnis;
// Anzahl der Gesamtpunktzahl
private int punkte;
// Zustand
int zustand; // 0: Aufgabe gestellt / 1: Antwort getippt
@FXML
private Button btnBack;
@FXML
void actBack(ActionEvent event) throws Exception{
Parent blah = FXMLLoader.load(getClass().getResource("main.fxml"));
Scene scene = new Scene(blah);
Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
appStage.setScene(scene);
appStage.show();
}
/*
* Wenn auf den Button geklickt wurde, wird diese Methode aufgerufen
* Je nach Zustand wird etwas anderes auf dem Button angezeigt und tut
* der Button auch etwas anderes
*/
@FXML
void buttonGeklickt(ActionEvent event) {
switch (zustand)
{
case 0: { // Zustand Aufgabe gestellt
// Es wird überprüft, ob die richtige Lösung eingegeben wurde
boolean ergebnis = a.loesungUeberpruefen();
if (ergebnis)
{
// Richtig
lblErgebnis.setText("Super!");
punkte = punkte + a.getPunkte();
lblPunkte.setText("" + punkte);
}
else
{
// Falsch
lblErgebnis.setText("Leider falsch");
}
// Der Zustand wird auf Antwort getippt gesetzt
zustand = 1;
button.setText("Weiter");
} break;
case 1: { // Zustand Antwort getippt
a.neu(); // Eine neue Aufgabe wird angezeigt
button.setText("Prüfen!");
lblErgebnis.setText("");
zustand = 0; // Zustand wird wieder auf Aufgabe gestellt gesetzt
}
Random r =new Random();
int i = r.nextInt(3);
if (i== 0)
{
a= new EinfacheAufgabe();
}
else if (i ==1)
{
a= new Minus();
}
else if (i ==2)
{
a =new Multi();
}
inhalt.getChildren().clear();
inhalt.getChildren().add(a.darstellungErstellen());
// Punktstand am Anfang ist 0
// Die Anwendung befindet sich im Zustand Aufgabe gestellt
zustand = 0;
lblErgebnis.setText("");
break;
}
}
/*
* Diese Methode wird aufgerufen, wenn alle Label und Button vom Loader erstellt worden sind
*/
@FXML
void initialize() {
Random r =new Random();
int i = r.nextInt(3);
if (i== 0)
{
a= new EinfacheAufgabe();
}
else if (i ==1)
{
a= new Minus();
}
else if (i ==2)
{
a =new Multi();
}
// fügt die Darstellung der einfachen Aufgabe in die Oberfläche ein
inhalt.getChildren().add(a.darstellungErstellen());
// Punktstand am Anfang ist 0
punkte = 0;
// Die Anwendung befindet sich im Zustand Aufgabe gestellt
zustand = 0;
lblErgebnis.setText("");
}
}