Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. package gui;
  2.  
  3. import javafx.concurrent.Task;
  4. import javafx.fxml.FXML;
  5. import javafx.fxml.Initializable;
  6. import javafx.scene.control.Button;
  7.  
  8. import java.net.URL;
  9. import java.util.ResourceBundle;
  10.  
  11. public class Controller extends Thread implements Initializable {
  12.  
  13. private boolean buttonStatus = false;
  14. @FXML
  15. Button btn_switch;
  16.  
  17. @FXML
  18. Button btn_sound;
  19.  
  20. @Override
  21. public void initialize(URL location, ResourceBundle resources) {
  22. System.out.println(buttonStatus);
  23. Task<Void> task = new SoundLoop();
  24. Thread thread = new Thread(task);
  25. thread.setDaemon(true);
  26. thread.start();
  27. }
  28.  
  29. public void playSound() {
  30. System.out.println("Playing sound.");
  31. }
  32.  
  33. public void toggleButton() {
  34. buttonStatus = !buttonStatus;
  35. System.out.println("Toggled button! " + buttonStatus);
  36. }
  37.  
  38. private class SoundLoop extends Task<Void> {
  39.  
  40. public SoundLoop() {
  41. playSound();
  42. if (buttonStatus) {
  43. playSound();
  44. }
  45. else {
  46. System.out.println(!buttonStatus);
  47. }
  48. }
  49.  
  50. @Override
  51. protected Void call() throws Exception {
  52. return null;
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement