红衣枪兵 红衣枪兵
关注数: 95 粉丝数: 286 发帖数: 2,500 关注贴吧数: 292
有会JAVA的大神么,求救,急用~~~ ////scollbar使用 常用的方法setValue(int a) getValue() /////构造函数new Scrollbar(横竖参数 0横1竖 ,初始数值,拖块大小,最小值,最大值) //////maximum是value+拖块的可视量 import java.awt.*; import java.util.Random; class checkWin{ public static Boolean frist=false; public static Boolean isWin=false; public static Label title=new Label("赛跑程序"); public static String Winer(ScollB scoll){    isWin=true;    return scoll.name; } } public class ScollB extends Scrollbar implements Runnable{ String name; Random rnd; ScollB(int sc,int sval,int bm,int min,int max,String n){    super(sc,sval,bm,min,max);    this.name=n;    rnd=new Random();    rnd.setSeed((rnd.nextInt(1245674)+1234534));/////这个是随机数乱数种子 刚开始是弄了个int常数,三个线程一跑 把把并列第一 } public void run(){    int s=0;    synchronized(checkWin.frist){          checkWin.title.setText(checkWin.title.getText()+" 起跑 :"+this.name); ///从起跑顺序来看 第一个start的线程总是第一的 第二第三随机 不知道怎么理解JVM的线程管理        }    while(!checkWin.isWin){     if(getValue()<(getMaximum()-getVisibleAmount())){     //synchronized(this){     int rd=rnd.nextInt(18)+2;     //}     s+=rd;         setValue(s);      try{       Thread.sleep(80);      }catch(Exception e){}     }     else{      checkWin.title.setText(checkWin.title.getText()+"    获胜者:"+checkWin.Winer(this));     }    }     } public static void main(String args[]){    Frame fm=new Frame("赛跑程序");    fm.setLayout(new GridLayout(4,1));    ScollB c1=new ScollB(0,0,1,0,600,"周星驰");    ScollB c2=new ScollB(0,0,1,0,600,"奥特曼");    ScollB c3=new ScollB(0,0,1,0,600,"奥巴马");       fm.add(checkWin.title);    fm.add(c1);    fm.add(c2);    fm.add(c3);    fm.setSize(700,120);    fm.setLocation(100,0);    fm.setVisible(true);    new Thread(c1).start();    new Thread(c2).start();    new Thread(c3).start(); } } 要求每行表上注释。 剩下的搞不定了。 各位看在圆神份上拉我一把~~
首页 1 2 下一页