Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. private void startJamJButtonActionPerformed(java.awt.event.ActionEvent evt) {
  2. if (startJamJButton.getText().equalsIgnoreCase("Start Jam")) {
  3. jamTimeJTextField.setText("Jam #" + jamNum + " 2:00");
  4. startJamJButton.setText("End Jam");
  5. doWork_startJam = true;
  6. } else if (startJamJButton.getText().equalsIgnoreCase("End Jam")) {
  7. startJamJButton.setText("Start Jam");
  8. firstTime_startJam = false;
  9. jamTimeJTextField.setText("Jam #" + jamNum + " 0:30");
  10. }
  11.  
  12. ActionListener taskPerformer = new ActionListener() {
  13. public void actionPerformed(ActionEvent e) {
  14. if (!doWork_startJam) {
  15. return;
  16. }
  17. String initial = jamTimeJTextField.getText();
  18. String[] time = initial.split(":"); // 2:00
  19. initial = initial.substring(0, initial.length() - 4);
  20.  
  21. int min = Integer.parseInt(time[0].substring(time[0].length() - 1)); // Jam # 2
  22. int sec = Integer.parseInt(time[1]);
  23. if (sec == 00) {
  24. min--;
  25. sec = 59;
  26. } else {
  27. sec--;
  28. }
  29. if (sec < 10) {
  30. jamTimeJTextField.setText(initial + min + ":0" + sec);
  31. } else {
  32. jamTimeJTextField.setText(initial + min + ":" + sec);
  33. }
  34.  
  35. if (min == 0 && sec == 0) {
  36. jamNum++;
  37. firstTime_startJam = false;
  38. doWork_startJam = false;
  39. startJamJButton.setText("Start Jam");
  40. }
  41. }
  42. };
  43.  
  44. Timer jamTimer = new Timer(startJamSpeed, taskPerformer);
  45. if (firstTime_startJam) {
  46. jamTimer.start();
  47. }
  48. }
  49.  
  50.  
  51. private void startJButtonActionPerformed(java.awt.event.ActionEvent evt) {
  52.  
  53. if (startJButton.getText().equalsIgnoreCase("Start")) {
  54. if (timerJTextField.getText().equals("0:00"))
  55. timerJTextField.setText("20:00");
  56. startJButton.setText("Pause");
  57. doWork_start = true;
  58. } else if (startJButton.getText().equalsIgnoreCase("Pause")) {
  59. startJButton.setText("Start");
  60. firstTime_start = false;
  61. doWork_start = false;
  62. }
  63.  
  64. ActionListener taskPerformer = new ActionListener() {
  65. public void actionPerformed(ActionEvent e) {
  66. if (!doWork_start) {
  67. return;
  68. }
  69. String initial = timerJTextField.getText();
  70. String[] time = initial.split(":"); // 20:00
  71.  
  72. int min = Integer.parseInt(time[0]); // 20
  73. int sec = Integer.parseInt(time[1]); // 00
  74. if (sec == 00) {
  75. min--;
  76. sec = 59;
  77. } else {
  78. sec--;
  79. }
  80. if (sec < 10) {
  81. timerJTextField.setText(min + ":0" + sec);
  82. } else {
  83. timerJTextField.setText(min + ":" + sec);
  84. }
  85.  
  86. if (min == 0 && sec == 0) {
  87. firstTime_start = false;
  88. doWork_start = false;
  89. startJButton.setText("Start");
  90. }
  91. }
  92. };
  93.  
  94. Timer startTimer = new Timer(startSpeed, taskPerformer);
  95. if (firstTime_start) {
  96. startTimer.start();
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement