CentralControl_TimeLine1
  • unsafe Time_Line
code:

package javafxtemplate1;
//Central Controller Class
import java.sql.SQLException;
import java.io.IOException;
import java.util.Date;
import javafx.util.Duration;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
//
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class JavaFXTemplate1 extends Application {


@Override
public void start(Stage primaryStage) throws IOException, SQLException {
CentralController controller = new CentralController();
Scene scene = new Scene(controller.getRoot(), 400, 300);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFx VBox");
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

//----
class CentralController {
private final VBox root;
private final Label label1, label2;
//RadialGradient gradient1;
int r1 , g1 , b1;
private final Circle ball;
public CentralController() {

root = new VBox();
label1 = new Label("Central control!");
label2 = new Label("Central control!");
label1.setLayoutY(100);label1.setLayoutX(100);
Button btn1 = new Button("Start");
Button btn2 = new Button("exit");
ball = new Circle(100, 100, 100);
label2.setText("started " +new Date().toString());
root.getChildren().addAll(label1,label2,btn1, btn2);
root.setSpacing(8);
btn1.setOnAction(new DemoEventHandler1());
btn2.setOnAction(new DemoEventHandler2());
}
public VBox getRoot() {
return root;
}
//
public void setupTimeline(){
KeyFrame kf = new KeyFrame(Duration.seconds(1),new DemoEventHandler1());
Timeline timeline = new Timeline(kf);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
}

//
private class DemoEventHandler1 implements EventHandler<ActionEvent>{
@Override
public void handle(ActionEvent event) {
//Platform.exit();
setupTimeline();
Date now = new Date();
label1.setText(now.toString());

}
}
private class DemoEventHandler2 implements EventHandler<ActionEvent>{
@Override
public void handle(ActionEvent event) {
Platform.exit();
}
}
}// end of controller
 

Displays:

First, Application start time, and then clock  counter display starts with an event handler.