Skip to content

Instantly share code, notes, and snippets.

@Filmaluco
Created June 15, 2023 20:45
Show Gist options
  • Save Filmaluco/a09e5ca14c85247c2edae9a90cd07b0d to your computer and use it in GitHub Desktop.
Save Filmaluco/a09e5ca14c85247c2edae9a90cd07b0d to your computer and use it in GitHub Desktop.
package pt.isec.pa.pong.ui;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.event.ActionEvent;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import pt.isec.pa.pong.model.Game;
import java.net.URL;
import java.util.ResourceBundle;
public class CommandsPane implements Initializable {
public HBox root;
public Button btnStart;
public Button btnPause;
public Button btnResume;
CommandsViewModel commandsViewModel;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
root.sceneProperty().addListener((observableValue, olsScene, newScene) -> {
commandsViewModel = new CommandsViewModel((Game) newScene.getUserData());
registerHandlers();
update();
});
}
private void registerHandlers() {
btnStart.disableProperty().bind(commandsViewModel.btStart);
btnPause.disableProperty().bind(commandsViewModel.bdPause);
btnResume.disableProperty().bind(commandsViewModel.bdResume);
}
private void update() { }
public void onStart(ActionEvent ignoredEvent) {
commandsViewModel.start();
}
public void onPause(ActionEvent ignoredEvent) {
commandsViewModel.pause();
}
public void onResume(ActionEvent ignoredEvent) {
commandsViewModel.resume();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment