Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.util.Calendar;
- import java.util.List;
- import javax.swing.SwingWorker;
- public class Clock extends SwingWorker<Void, Void>{
- ClockGUI myGUI;
- public int counter = 1;
- public Clock(ClockGUI gui){
- myGUI = gui;
- }
- public void Alarm() throws InterruptedException{
- }
- @SuppressWarnings("null")
- protected Void doInBackground() throws Exception {
- while(isCancelled() == false)
- {
- //System.out.println(11-counter);
- counter++;
- this.publish();
- Thread.sleep(1000);
- if(counter>10){
- System.out.println("RING!!!WAKE UP!!!");
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- myGUI.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- SwingWorker<Void, Void> wrk = null;
- wrk.cancel(true);
- }
- }
- return null;
- }
- protected void process(List<Void> chunks) {
- Calendar myTime = Calendar.getInstance();
- myGUI.setTime(myTime.get(Calendar.HOUR_OF_DAY), myTime.get(Calendar.MINUTE),myTime.get(Calendar.SECOND));
- }
- }
Add Comment
Please, Sign In to add comment