Last active
December 21, 2015 06:18
-
-
Save skrb/6262796 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import javafx.animation.AnimationTimer; | |
import javafx.application.Application; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Label; | |
import javafx.scene.input.MouseEvent; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.media.AudioClip; | |
import javafx.scene.paint.Color; | |
import javafx.scene.text.Font; | |
import javafx.stage.Stage; | |
import javafx.stage.StageStyle; | |
public class Gong extends Application { | |
private static DateFormat formatter = new SimpleDateFormat("m:ss"); | |
private AnimationTimer timer; | |
private Label label; | |
private static final long M = 1_000_000; | |
private static final long FIVE = 300_000; | |
private long start = 0; | |
private long diff = 0; | |
@Override | |
public void start(Stage stage) { | |
StackPane root = new StackPane(); | |
root.setPrefSize(1024, 768); | |
root.setOnMousePressed(new EventHandler<MouseEvent>() { | |
@Override | |
public void handle(MouseEvent t) { | |
if (diff == 0) { | |
timer.start(); | |
} | |
} | |
}); | |
label = new Label("5:00"); | |
label.setFont(Font.font("Arial Black", 380)); | |
label.setScaleY(2.0); | |
label.setStyle("-fx-text-fill: white;"); | |
root.getChildren().add(label); | |
Scene scene = new Scene(root, 1024, 768); | |
scene.setFill(Color.BLACK); | |
stage.setScene(scene); | |
stage.initStyle(StageStyle.UNDECORATED); | |
stage.show(); | |
final AudioClip clip = new AudioClip(getClass().getResource("gong.wav").toString()); | |
timer = new AnimationTimer() { | |
@Override | |
public void handle(long now) { | |
if (start == 0) { | |
start = now; | |
} | |
if ((now - start)/M - diff > 1_000) { | |
diff += 1_000; | |
String time = formatter.format(new Date(FIVE - diff)); | |
label.setText(time); | |
} | |
if (diff == FIVE) { | |
clip.play(); | |
timer.stop(); | |
diff = 0; | |
start = 0; | |
} | |
} | |
}; | |
} | |
public static void main(String... args) { | |
launch(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment