刚学java这东西,遇到个小问题,希望帮忙解决一下
<code>import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.math.*;
public class TimeFrame {
private JFrame jf;
private JLabel label1;
private JLabel label2;
public TimeFrame(){
jf=new JFrame("北京奥运会开幕式倒计时牌");
label1=new JLabel("距2008年北京奥运会开幕还有:");
label2=new JLabel("");
label1.setFont(new Font("宋休",Font.BOLD,28));
label2.setFont(new Font("宋休",Font.BOLD,40));
jf.setLayout(new FlowLayout());
label1.setForeground(Color.BLUE);
label2.setForeground(Color.CYAN);
jf.add(label1);
jf.add(label2);
show();
// jf.setResizable(false);
new RefreshTimeTread().start();
}
private void show(){
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setSize(1000, 300);
}
class RefreshTimeTread extends Thread{
// private int d=(int)((Math.random()+0.1)*100);
public void run() {
Calendar target=new GregorianCalendar(2008,7,8,20,8,8);
while(true){
Calendar now=new GregorianCalendar();
long time=(target.getTimeInMillis()-now.getTimeInMillis())/1000;//得到相隔的秒数
if(time<=0){
label2.setText("时间到!!");
break;
}
long d,h,m,s;
d=time/(60*60*24);
h=time%(60*60*24)/60/60;
m=time%(60*60*24)%(60*60)/60;
s=time%(60*60*24)%(60*60)%60;
label2.setText(d+"天"+h+"小时"+m+"分"+s+"秒") ;
// label2.setForeground(new Color(d,d,d));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}//while
} //run
} //class
public static void main(String []args){
TimeFrame tf=new TimeFrame();
}
}
</code>
我是想让这个程序在显示的时候能够随机变色,自己写的那个有错误,不知道怎么写,麻烦大家看一下