السلام عليكم
ياجماعة الخير ... كتبت كود لعرض الساعة على JLabel اوكي ...
وكل شي ماشي تمام لكن المشكله ان الساعة ماتطلع إلا بعد تغيير حجم الفريم
ليتم العرض :( :( مدري وش المشكله اتمنى فيه احد يعرفها
هذا هو الكود
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class Time1 extends JFrame implements Runnable{
private Thread current;
private JLabel time=new JLabel();
private int hour, minute,second;
private DecimalFormat timeFormat = new DecimalFormat("00");
public Time1()
{
super("Time");
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(time);
start();
}
public void start()
{
current = new Thread(this);
current.start();
}
public void run()
{
Thread thread = Thread.currentThread();
while(thread == current){
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
Calendar now = Calendar.getInstance();
hour = now.get(Calendar.HOUR_OF_DAY);
minute = now.get(Calendar.MINUTE);
second = now.get(Calendar.SECOND);
time.setText("Time : "+timeFormat.format(hour)+":"+
timeFormat.format(minute)+":"+timeFormat.format(second));
}
}
public void stop(){}
public static void main(String [] args)
{
Time1 time = new Time1();
time.setVisible(true);
time.setSize(150,60);
time.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}