Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.mah.negash.dClock;
- import javax.swing.SwingWorker;
- import java.awt.Color;
- import java.util.Calendar;
- import java.util.List;
- import java.util.Timer;
- public class Clock extends SwingWorker<Void, Void> {
- ClockGUI clockG;
- private int time_hours;
- private int time_minutes;
- private int alarm_hours;
- private int alarm_minutes;
- String time;
- public int counter = 1;
- public Clock(ClockGUI gui){
- clockG=gui;
- }
- @Override
- protected Void doInBackground() throws Exception {
- while(isCancelled() == false)
- {
- counter++;
- this.publish();
- Thread.sleep(1000);
- if(counter>10){
- System.out.println("RING!!!WAKE UP!!!");
- clockG.setNewBackground(new Color((float) Math.random(), (float) Math.random(),(float) Math.random()));
- Thread.sleep(300);
- SwingWorker<Void, Void> myClock = null;
- myClock.cancel(true);
- }
- }
- return null;
- }
- @Override
- protected void process(List<Void> chunks) {
- Calendar myTime = Calendar.getInstance();
- clockG.setTime(myTime.get(Calendar.HOUR_OF_DAY), myTime.get(Calendar.MINUTE),myTime.get(Calendar.SECOND));
- }
- public void setAlarm(int hours, int minutes){
- clockG.setNewBackground(new Color((float) Math.random(), (float) Math.random(),
- (float) Math.random()));
- }
- }
Add Comment
Please, Sign In to add comment