summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-04-27 21:44:11 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-04-27 21:44:11 +0200
commitd1a8c2522dd10ca112ccda0cf1407814b772e6e6 (patch)
tree5f72b2a5a7fcc3c460a9777cab60f836fee0fe18 /src/de/fhswf/in
parent56fec9fd33949003ffdcb1132a2aa2a6a3cf444f (diff)
downloadJava2-d1a8c2522dd10ca112ccda0cf1407814b772e6e6.tar.gz
Java2-d1a8c2522dd10ca112ccda0cf1407814b772e6e6.zip
Stop the interval on command or after firing the action event
Diffstat (limited to 'src/de/fhswf/in')
-rw-r--r--src/de/fhswf/in/inf/java2/aufgabe04/CountdownExitButton.java48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/de/fhswf/in/inf/java2/aufgabe04/CountdownExitButton.java b/src/de/fhswf/in/inf/java2/aufgabe04/CountdownExitButton.java
index b859b8f..4ba5bf2 100644
--- a/src/de/fhswf/in/inf/java2/aufgabe04/CountdownExitButton.java
+++ b/src/de/fhswf/in/inf/java2/aufgabe04/CountdownExitButton.java
@@ -39,20 +39,21 @@ public class CountdownExitButton extends Button
timeline
.getKeyFrames()
.add(new KeyFrame(
- Duration.seconds(1),
- (e -> {
+ Duration.seconds(1),
+ (e -> {
CountdownExitButton.this
- .setText(CountdownExitButton.this
- .getText()
- .replaceFirst(
- "\\("
- + CountdownExitButton.this.countdown
- + "\\)$",
- "("
- + --CountdownExitButton.this.countdown
- + ")"));
+ .setText(CountdownExitButton.this
+ .getText()
+ .replaceAll(
+ "\\("
+ + CountdownExitButton.this.countdown
+ + "\\)$",
+ "("
+ + --CountdownExitButton.this.countdown
+ + ")"));
if (CountdownExitButton.this.countdown <= 0)
{
+ CountdownExitButton.this.stopCountdown();
CountdownExitButton.this.fire();
}
})));
@@ -64,11 +65,22 @@ public class CountdownExitButton extends Button
*/
public void startCountdown()
{
- super.setText(getText() + " (" + countdown + ")");
+ setText(getText() + " (" + countdown + ")");
timeline.playFromStart();
}
/**
+ * Stops the countdown without the button fire event.
+ *
+ */
+ public void stopCountdown()
+ {
+ timeline.stop();
+ setText(getText().replaceAll(
+ "\\(" + CountdownExitButton.this.countdown + "\\)$", ""));
+ }
+
+ /**
* Set the countdown.
*
* @param countdown
@@ -86,12 +98,20 @@ public class CountdownExitButton extends Button
/**
* Get the countdown.
*
- * @return
- * The countdown in seconds.
+ * @return The countdown in seconds.
*/
public int getCountdown()
{
return countdown;
}
+ /* (non-Javadoc)
+ * @see javafx.scene.control.Button#fire()
+ */
+ @Override
+ public void fire()
+ {
+ stopCountdown();
+ super.fire();
+ }
}