随笔-4  评论-4  文章-0  trackbacks-0
  2008年8月14日

package youg;

import java.util.Date;
import java.util.Random;

public class hiden {
 public int rand()
 {
  int sta=1;
  
  //Date d=new Date();
  double time=System.currentTimeMillis();
  Random r=new Random();
  sta=r.nextInt((int)time%1000)%10;
  System.out.println(sta);
  return sta;
 }
 
 public static void main(String args[])
 {
  hiden h=new hiden();
  System.out.println(h.rand());
 }

}

posted @ 2008-08-14 11:30 志遥 阅读(172) | 评论 (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 @ 2008-08-14 11:29 志遥 阅读(184) | 评论 (0)编辑 收藏
     摘要: /* *此小程序的基本流程是,在一个文本文件存放里面备选的数据,数据的格式是每行有姓名 和 手机号 *他们之间是用分隔符-来分隔的。然后在自定义一个方法,通过分隔符来区分姓名和手机号,然后将 *他们分别存储进两个不同的可变向量当中。 *   自定义一个线程,此线程是专门用来随机选取一个号码, 并且每隔50毫秒就将一个不同的号码显示在 *   号码框...  阅读全文
posted @ 2008-08-14 11:29 志遥 阅读(288) | 评论 (0)编辑 收藏