Guest User

Untitled

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