Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Thread;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author LYCOCO
- */
- public class Clock implements Runnable{
- private int hour;
- private int minute;
- private int second;
- private int alarmH;
- private int alarmM;
- private int alarmS;
- Clock(int hour,int minite,int second){
- this.hour = hour;
- this.minute = minite;
- this.second = second;
- }
- public void run(){
- while(true){
- second ++;
- if(second == 60){
- minute++;
- second = 0;
- }
- if(minute == 60){
- hour++;
- minute = 0;
- }
- if(hour == 24){
- hour = 0;
- }
- System.out.println(this);
- try{
- Thread.sleep(1000);
- this.runAlarm();
- } catch(InterruptedException ex){
- ex.printStackTrace();
- }
- }
- }
- @Override
- public String toString(){
- return "Hour:" + this.hour + " Minute:" + this.minute + " Second:" + this.second;
- }
- public void setAlarm(int hour,int minite,int second){
- this.alarmH = hour;
- this.alarmM = minite;
- this.alarmS = second;
- }
- public void runAlarm(){
- if(this.hour == this.alarmH && this.minute == this.alarmM && this.second == this.alarmS){
- for(int i = 0;i<10;i++){
- System.out.println("GET UP !");
- }
- }
- }
- public static void main(String args[]) {
- Clock a = new Clock(23,59,57);
- Thread t = new Thread(a);
- t.start();
- a.setAlarm(0, 0, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement