Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package view;
- import java.time.LocalTime;
- import java.time.format.DateTimeFormatter;
- import java.util.Timer;
- import java.util.TimerTask;
- import javafx.animation.KeyFrame;
- import javafx.animation.KeyValue;
- import javafx.animation.Timeline;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.event.Event;
- import javafx.event.EventHandler;
- import javafx.geometry.Pos;
- import javafx.scene.control.Label;
- import javafx.scene.layout.FlowPane;
- import javafx.scene.shape.Rectangle;
- import javafx.util.Duration;
- public class WelcomeFP extends FlowPane{
- private Label lblTime;
- private Timeline tlMinute;
- private Rectangle rect;
- public WelcomeFP() {
- super();
- this.getChildren().add(getLblTime());
- this.setAlignment(Pos.TOP_CENTER);
- }
- public Label getLblTime() {
- if(lblTime == null) {
- lblTime = new Label("Time: ");
- /*
- Thread timeThread = new Thread(new Runnable() {
- @Override
- public void run() {
- while(true) {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- lblTime.setText(LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
- }
- });
- try {
- if(Thread.interrupted()) {
- return;
- }
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- return;
- }
- }
- }
- });
- timeThread.setDaemon(true);
- timeThread.start();
- */
- /*
- TimerTask task = new TimerTask() {
- @Override
- public void run() {
- //while(true) {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- lblTime.setText(LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
- }
- });
- /*
- try{
- if(Thread.interrupted()) {
- return;
- }
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- return;
- }
- //}
- }
- };
- Timer timer = new Timer(true); // pour le rendre deamon thread
- timer.scheduleAtFixedRate(task, 0, 1000);
- */
- KeyFrame keyFrame = new KeyFrame(Duration.seconds(1), new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent arg0) {
- lblTime.setText(LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")));
- }
- });
- Timeline timeLine = new Timeline(keyFrame);
- timeLine.setCycleCount(Timeline.INDEFINITE);
- timeLine.playFromStart();
- }
- return lblTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement