Guest User

Untitled

a guest
Jun 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.util.Calendar;
  3. import java.util.List;
  4.  
  5. import javax.swing.SwingWorker;
  6.  
  7.  
  8. public class Clock extends SwingWorker<Void, Void>{
  9.  
  10. ClockGUI myGUI;
  11. public int counter = 1;
  12.  
  13. public Clock(ClockGUI gui){
  14. myGUI = gui;
  15.  
  16. }
  17.  
  18. public void Alarm() throws InterruptedException{
  19.  
  20.  
  21.  
  22.  
  23. }
  24.  
  25. @SuppressWarnings("null")
  26. protected Void doInBackground() throws Exception {
  27.  
  28. while(isCancelled() == false)
  29. {
  30. //System.out.println(11-counter);
  31. counter++;
  32.  
  33. this.publish();
  34. Thread.sleep(1000);
  35.  
  36. if(counter>10){
  37. System.out.println("RING!!!WAKE UP!!!");
  38. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  39. Thread.sleep(300);
  40. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  41. Thread.sleep(300);
  42. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  43. Thread.sleep(300);
  44. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  45. Thread.sleep(300);
  46. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  47. Thread.sleep(300);
  48. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  49. Thread.sleep(300);
  50. myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
  51. SwingWorker<Void, Void> wrk = null;
  52. wrk.cancel(true);
  53.  
  54. }
  55.  
  56.  
  57.  
  58. }
  59. return null;
  60. }
  61.  
  62. protected void process(List<Void> chunks) {
  63. Calendar myTime = Calendar.getInstance();
  64. myGUI.setTime(myTime.get(Calendar.HOUR_OF_DAY), myTime.get(Calendar.MINUTE),myTime.get(Calendar.SECOND));
  65. }
  66. }
Add Comment
Please, Sign In to add comment