05 July 2016

Show System Date and Time in JFrame ( Dynamic Clock ) Java Eclipse GUI

Show System Date and Time in JFrame ( Dynamic Clock )
Java 2016
public void clock(){
 Thread clock = new Thread(){
  public void run(){
   try {
    while(true){
     Calendar cal = new GregorianCalendar();
     int second = cal.get(Calendar.SECOND);
     int minute = cal.get(Calendar.MINUTE);
     int hour = cal.get(Calendar.HOUR);
     lblTime.setText(hour +":"+ minute +":"+ second);
     sleep(1000);
    }
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 };
 clock.start();
}

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang