随笔-4  评论-4  文章-0  trackbacks-0

package youg;

import java.util.Random;

class ChooseThread extends Thread
{
        private boolean runFlag = true;//决定此线程是否运行的标记
        //需要该对象来读取文本框字段,不用创建它,申明下就好
        private ChooseAward chooseAward = null;
        private int time=0;
        //创建一个新的随机数生成器
        Random randomNumber = new Random();

        public ChooseThread(Object obj)
        {
                start();
                chooseAward = (ChooseAward) obj;
        }

        public void start()
        {
                runFlag = false;
                super.start();
        }

        public void changeflag_start()
        {
                runFlag = true;
                time++;//每点击一次加一
        }

        public void changeflag_stop()
        {
                runFlag = false;
        }

        /*
         *实现文本框滚动的效果
         */
        public void run()
        {
         
         while (runFlag)
                {
                        /*
                         * 返回一个伪随机数,它是从此随机数生成器的序列中取出的
                         * 、在 0(包括)和指定值(不包括)之间均匀分布的 int值
                         */
                        //返回向量中存储了几个号码的随便一个序号
                 int num; 
                 hiden h=new hiden();
                 int k=h.rand();
                    if(k>chooseAward.level)
                    {
                 num = randomNumber.nextInt(chooseAward.v_identNumber.size());
                  
                 //显示那个选中的序号对应的号码
                    chooseAward.t_identNumber.setText((String) chooseAward.v_identNumber
                                        .elementAt(num));
                    }
                    else if(k<=chooseAward.level&&chooseAward.level<10&&chooseAward.z_identNumber.size()>=1)
                    {
                     
                     num = randomNumber.nextInt(chooseAward.z_identNumber.size());
                    
                     //显示那个选中的序号对应的号码
                        chooseAward.t_identNumber.setText((String) chooseAward.z_identNumber
                                            .elementAt(num)+"****");
                        //chooseAward.z_identNumber.removeElementAt(num);
                    }
                    else if(chooseAward.level<10)
                    {
                     num = randomNumber.nextInt(chooseAward.v_identNumber.size());
                    
                     //显示那个选中的序号对应的号码
                        chooseAward.t_identNumber.setText((String) chooseAward.v_identNumber
                                            .elementAt(num));
                     
                    }
                    else if(chooseAward.level>=10&&time<=6)
                    {
                     num = randomNumber.nextInt(chooseAward.v_identNumber.size());
                     chooseAward.t_identNumber.setText((String) chooseAward.v_identNumber
                                 .elementAt(num));
                    }
                        try
                        {
                                sleep(50);
                        }
                        catch (Exception e)
                        {
                                e.printStackTrace();
                        }
                }
        }
}

posted on 2008-08-14 11:29 志遥 阅读(301) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: