-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathState1Controller.java
75 lines (58 loc) · 2.07 KB
/
State1Controller.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package application;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ResourceBundle;
import javafx.animation.AnimationTimer;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
public class State1Controller implements Initializable{
// import methods from GlobalController as global
GlobalController global = new GlobalController();
@FXML private Text dateTime;
@FXML private Button logoutButton;
@FXML private AnchorPane anchorPane;
Stage stage;
public void switchToState2(ActionEvent e) throws IOException{
global.switchToState2(e);
}
public void switchToState5(ActionEvent e) throws IOException{
global.switchToState5(e);
}
public void logout(ActionEvent e){
Alert alert = new Alert(AlertType.CONFIRMATION);
alert.setTitle("Logout");
alert.setHeaderText("You're about to logout!");
alert.setContentText("Are you sure you want to leave?");
if (alert.showAndWait().get() == ButtonType.OK) {
stage = (Stage) anchorPane.getScene().getWindow();
System.out.println("logged out");
stage.close();
}
}
@Override
public void initialize(URL arg0, ResourceBundle arg1) {
// start the animation timer so the date will be dynamically updated every second
timer.start();
}
// create an animation object
AnimationTimer timer = new AnimationTimer() {
@Override
public void handle(long now) {
// set the dateTime Text to the current time with custom formatting
dateTime.setText(LocalDateTime.now().format(DateTimeFormatter.ofPattern("MMM-dd-yyyy HH:mm:ss")));
}
};
}