Guest User

Untitled

a guest
Jun 24th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 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.     ClockUI myGUI;
  11.     private int alarm_minute;
  12.     private int alarm_hour;
  13.     private int alarm_second;
  14.     private int hour;
  15.     private int minute;
  16.     private int _alarm;
  17.     private int counter = 1;
  18.     public Clock(ClockUI gui){
  19.         myGUI = gui;
  20.        
  21.     }
  22.    
  23.    
  24.     @Override
  25.     protected Void doInBackground() throws Exception {
  26.        
  27.         while(isCancelled() == false)
  28.         {
  29.         counter++; // räknare för alarm
  30. //  System.out.println("Run thread");
  31.         this.publish();
  32.         Thread.sleep(1000);
  33.        
  34.         // startat ett alarm om 10 sekunder
  35.           if(counter>10){
  36.               System.out.println("RING!!!WAKE UP!!!");
  37.               myGUI.invokeAlarm();
  38.               SwingWorker<Void, Void> myClock = null;
  39.               myClock.cancel(true);
  40.           }
  41.         }
  42.  
  43. return null;
  44. }  
  45.    
  46.    
  47.     protected void process(List<Void> chunks) {
  48.          Calendar myTime = Calendar.getInstance();
  49.        
  50.          myGUI.setTime(myTime.get(Calendar.HOUR_OF_DAY), myTime.get(Calendar.MINUTE),  myTime.get(Calendar.SECOND));
  51.    
  52.     }
  53.     }
Add Comment
Please, Sign In to add comment