Skip to content

Commit 0ca7d30

Browse files
committed
feat: Increase the default value from zero every second
Resolves #6
1 parent 23b694d commit 0ca7d30

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

ProfCalculator/src/de/uulm/sp/swt/profcalculator/ProfCalculator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.uulm.sp.swt.profcalculator;
22

33
import de.uulm.sp.swt.profcalculator.expressions.Addition;
4+
import de.uulm.sp.swt.profcalculator.expressions.CounterValue;
45
import de.uulm.sp.swt.profcalculator.expressions.Expression;
56
import de.uulm.sp.swt.profcalculator.expressions.Multiplication;
67
import de.uulm.sp.swt.profcalculator.expressions.NecessaryBrackets;
@@ -21,9 +22,7 @@
2122

2223
public class ProfCalculator extends Application implements EventHandler<ActionEvent> {
2324

24-
private final static Value DEFAULT_VALUE = new Value(0);
25-
26-
private Expression expression = DEFAULT_VALUE;
25+
private Expression expression = new CounterValue(this);
2726

2827
private GUIFactory guiFactory = new BlueFontGUIFactory();
2928

@@ -72,7 +71,7 @@ else if (event.getSource() == multiplicationButton) {
7271
}
7372
}
7473

75-
private void updateGUI() {
74+
public void updateGUI() {
7675
resultLabel.setText(expression.computeEquation());
7776
inputField.setText("");
7877
errorLabel.setText("");
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.uulm.sp.swt.profcalculator.expressions;
2+
3+
import de.uulm.sp.swt.profcalculator.ProfCalculator;
4+
import javafx.application.Platform;
5+
6+
public class CounterValue extends Value implements Runnable {
7+
8+
ProfCalculator calc;
9+
10+
public CounterValue(ProfCalculator calc) {
11+
super(0);
12+
this.calc = calc;
13+
new Thread(this).start();
14+
}
15+
16+
@Override
17+
public void run() {
18+
while (value < 10) {
19+
try {
20+
Thread.sleep(1000);
21+
} catch (InterruptedException e) {
22+
}
23+
value++;
24+
Platform.runLater(new Runnable() {
25+
public void run() {
26+
calc.updateGUI();
27+
}
28+
});
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)