How to detect idle time in Javafx

757 Views Asked by At

Im searching for an example how to deal with idle times in javafx and found this perfect answer Idle time in javafx. But how i can add this in my Controller class because i create all on a Fxml class and call this like:

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/sample.fxml"));

so my question is how to get it work with register idle monitor and how i create the idle monitor

public class LoginController {

static final Logger logger = Logger.getLogger(Controller.class.getName());

@FXML
private ResourceBundle resources;

@FXML
private URL location;

@FXML
private AnchorPane anch;

@FXML
private TextField machineNumberField;

@FXML
private Label label;

private Label labelwrong = new Label();

private static Integer machineNumber;

public static Integer getMachineNumber() {
    return machineNumber;
}

public static void setMachineNumber(Integer machineNumber) {
    LoginController.machineNumber = machineNumber;
}

@FXML
void initialize() {}

@FXML
void onEnterMachineNumber(ActionEvent event) throws IOException {
    PlatformHelper platformHelper = new PlatformHelper();
    String machineNumber = machineNumberField.getText();

    if (!machineNumber.isEmpty() && machineNumber.contains("$")) {
        DbConnection dbConnection = new DbConnection();
        try {
            dbConnection.Connect();
            FileReaderWriter fileReaderWriter = new FileReaderWriter("thread");
            if(fileReaderWriter.isCacheFileNotEmpty()) {
                fileReaderWriter.copyCacheFile();
                fileReaderWriter.flushStorageFile(null);
                fileReaderWriter.start();
            }
        } catch (SQLException e) {
            logger.error("SQL Exception " + machineNumberField.getText() + "\n" + e.getMessage());
        }
        try {
            String machinenr = machineNumber.split("\\$")[1];
            setMachineNumber(Integer.parseInt(machinenr));
            FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/sample.fxml"));
            Parent root = fxmlLoader.load();
            Controller controller = fxmlLoader.getController();
            controller.setMachineNumber(getMachineNumber());

            anch.getChildren().clear();
            anch.getChildren().add(root);
        } catch (NumberFormatException e) {
            platformHelper.displayWarning(anch, labelwrong, "wrong Barcode");
            machineNumberField.clear();
            logger.info("Wrong Barcode format exception " + machineNumberField.getText() + "\n" + e.getMessage());
        }

    } else {
        platformHelper.displayWarning(anch, labelwrong, "wrong Barcode");
        machineNumberField.clear();
        logger.info("Wrong Barcode format exception " + machineNumberField.getText());
    }


}}

Edit:

Main.java

public class Main extends Application {

Scene loginScene;

@Override
public void start(Stage primaryStage) throws Exception {
    StackPane root = new StackPane();

    Parent login = FXMLLoader.load(getClass().getResource("/login.fxml"));
    primaryStage.setTitle("Timer for process time");

    loginScene = new Scene(login);
    primaryStage.setScene(loginScene);
    primaryStage.setFullScreen(true);
    primaryStage.show();



    setUserAgentStylesheet(STYLESHEET_MODENA);


    new FileReaderWriter("setPath").setPathandCacheFile();
}


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

}

0

There are 0 best solutions below