标题:刚学java这东西,遇到个小问题,希望帮忙解决一下
取消只看楼主
lhjq780
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-7-25
 问题点数:0 回复次数:0 
刚学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>
我是想让这个程序在显示的时候能够随机变色,自己写的那个有错误,不知道怎么写,麻烦大家看一下
搜索更多相关主题的帖子: java 北京奥运会 import new JLabel 
2008-07-25 19:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-225248-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.597265 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved