Page 443 - MDP2020-3
P. 443

················································································  명장양성프로젝트  【MDP】  과제발표회  자료집  Ⅲ    |  437




                    Handler  onHandler=new  Handler(){

                            @Override
                            public  void  handleMessage(Message  msg){
                                    int  mole=0;
                                    for  (int  i=0;i<img_array.length;i++){
                                            if  (img_array[i].getTag().toString().equals(TAG_ON)){

                                                    mole++;
                                            }
                                    }
                                    if  (mole==0)  {
                                            if  (t>0){

                                                    i m g _ a r r a y [ m s g . a r g 1 ] . s e t I m a g e R e s o u r c e ( i m g [ n e w
            Random().nextInt(3)]);
                                                    img_array[msg.arg1].setTag(TAG_ON);
                                            }
                                    }

                            }
                    };


                    Handler  offHandler=  new  Handler(){
                            @Override

                            public  void  handleMessage(Message  msg){
                                    img_array[msg.arg1].setImageResource(R.drawable.ground);
                                    img_array[msg.arg1].setTag(TAG_OFF);
                            }
                    };



                    public  class  DThread  implements  Runnable{
                            int  index=0;
                            DThread(int  index){
                                    this.index=index;

                            }


                            @Override
                            public  void  run(){
                                    while  (true){

                                            try  {
                                                    Message  msg1=new  Message();
                                                    int  offtime=new  Random().nextInt(1000)+500;
                                                    Thread.sleep(offtime);
   438   439   440   441   442   443   444   445   446   447   448