package fr.uca.iut.clfreville2.gui.thread; import fr.uca.iut.clfreville2.model.shared.Tickable; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleIntegerProperty; public class Ticker extends Thread { private final Tickable tickable; private final IntegerProperty millisPerTick = new SimpleIntegerProperty(250); private final BooleanProperty running = new SimpleBooleanProperty(true); public Ticker(Tickable tickable) { this.tickable = tickable; } @Override public void run() { while (true) { try { Thread.sleep(millisPerTick.getValue()); if (running.get()) { Platform.runLater(tickable::tick); } } catch (InterruptedException e) { break; } } } public int getMillisPerTick() { return millisPerTick.get(); } public void setMillisPerTick(int millisPerTick) { this.millisPerTick.set(millisPerTick); } public IntegerProperty millisPerTickProperty() { return millisPerTick; } public void setRunning(boolean running) { this.running.setValue(running); } public boolean getRunning() { return running.getValue(); } public BooleanProperty runningProperty() { return running; } }