this is the code for my class assignment
import java.util.Calendar;
class ClockThread implements Runnable,KeyListner{
int sec,min,hour;
Thread thr;
ClockThread(){
Calendar rightNow = Calendar.getInstance();
hour=rightNow.get(Calendar.HOUR);
min=rightNow.get(Calendar.MINUTE);
sec=rightNow.get(Calendar.SECOND);
thr=new Thread(this);
thr.start();
}
public void run(){
while(true){
try{
Thread.sleep(1000);
sec++;
}
catch(InterruptedException ie){
System.out.println(ie);
}
if(sec>=59){
sec=0;
min++;
}
if(min>=59){
min=0;
hour++;
}
if(hour>=11){
hour=0;
}
System.out.format("\r%02d:%02d:%02d",hour,min,sec);
}}
}
class Clock{
public static void main(String args[]){
new ClockThread();
}}
what i want is that instead of while(true) i can put some sorta event handler which breaks in event of a KeyDown.
please help me out here..