Created
December 3, 2013 00:47
-
-
Save skrb/7761966 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package simpleclock; | |
import java.util.Date; | |
import javafx.animation.KeyFrame; | |
import javafx.animation.Timeline; | |
import javafx.application.Application; | |
import javafx.event.ActionEvent; | |
import javafx.event.EventHandler; | |
import javafx.scene.Scene; | |
import javafx.scene.control.Label; | |
import javafx.scene.layout.StackPane; | |
import javafx.scene.text.Font; | |
import javafx.stage.Stage; | |
import javafx.util.Duration; | |
public class SimpleClock extends Application { | |
@Override | |
public void start(Stage stage) { | |
StackPane root = new StackPane(); | |
Label label = new Label(); | |
label.setFont(Font.font(null, 18.0)); | |
root.getChildren().add(label); | |
Scene scene = new Scene(root, 300, 50); | |
stage.setTitle("Simple Clock"); | |
stage.setScene(scene); | |
stage.show(); | |
// ラベルの文字列を更新するタイマを起動する | |
startTimer(label); | |
} | |
private void startTimer(final Label label) { | |
Timeline timeline = new Timeline( | |
new KeyFrame(Duration.millis(1_000), | |
new EventHandler<ActionEvent>() { | |
@Override | |
public void handle(ActionEvent t) { | |
// 1秒ごとにラベルの文字列を更新する | |
label.setText(new Date().toString()); | |
} | |
}) | |
); | |
timeline.setCycleCount(Timeline.INDEFINITE); | |
timeline.play(); | |
} | |
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