Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import javafx.concurrent.Task;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Button;
- import java.net.URL;
- import java.util.ResourceBundle;
- public class Controller extends Thread implements Initializable {
- private boolean buttonStatus = false;
- @FXML
- Button btn_switch;
- @FXML
- Button btn_sound;
- @Override
- public void initialize(URL location, ResourceBundle resources) {
- System.out.println(buttonStatus);
- Task<Void> task = new SoundLoop();
- Thread thread = new Thread(task);
- thread.setDaemon(true);
- thread.start();
- }
- public void playSound() {
- System.out.println("Playing sound.");
- }
- public void toggleButton() {
- buttonStatus = !buttonStatus;
- System.out.println("Toggled button! " + buttonStatus);
- }
- private class SoundLoop extends Task<Void> {
- public SoundLoop() {
- playSound();
- if (buttonStatus) {
- playSound();
- }
- else {
- System.out.println(!buttonStatus);
- }
- }
- @Override
- protected Void call() throws Exception {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement