首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2ME开发 >

J2ME 键盘没有响应急求()

2012-01-02 
J2ME 键盘没有响应急求(在线等)远程控制网络摄像头按键之后没有反映,苦恼中publicclassGetCanvasextendsGa

J2ME 键盘没有响应急求(在线等)
远程控制网络摄像头按键之后没有反映,苦恼中
public   class   GetCanvas   extends   GameCanvas   implements     Runnable   {

protected   Get   get;
protected   Thread   thread;
                protected   int   sign,   sign1;
                private   Graphics   graphics;
                Image   im;
                Image   t;
                public   Form   fmViewPng;

        private   boolean   sleeping;
                private   Display   display;
               
public   GetCanvas(){
                        super(false);
                        fmViewPng=new   Form( " ");
                }
                           
            public   void   start()   {
                sleeping   =   false;
                thread=new   Thread(this);
                //input();
                thread.start();
                }

            public   void   stop(){
                  sleeping   =   true;
            }
public   void   run(){
                           
                      Graphics   g   =   getGraphics();
                          while   (!sleeping){    
                              input();
                      /*               try{  
                                                System.out.println( "Connect   server   error ");
                                                String   url   =   "http://193.60.171.10/cgi-bin/camctrl.cgi?move=left ";
                                                HttpConnection   connection   =(HttpConnection)Connector.open(url);  
                                                InputStream   iStrm   =   connection.openInputStream();


                                                }catch   (IOException   ioe)   {}*/
                          //       keyPressed(4);
                              try{
                                  Image   im;
                                  if((im=getImage())!=null){
                                  ImageItem   ii=new   ImageItem(null,im,ImageItem.LAYOUT_DEFAULT,null);
                                  if(fmViewPng.size()!=0)
                                  fmViewPng.set(0,ii);
                          else
                                  fmViewPng.append(ii);
                      //             input();
                                }
                            else{
                                          fmViewPng.append( "Unsuccessful   download. ");
                                          }
                                }
                                catch(Exception   e){
                                  System.err.println( "Msg: "+e.toString());
                          }//input();
                              //     Display.getDisplay(get).setCurrent(fmViewPng);
                //   display.setCurrent(fmViewPng);
                             
                          try   {                      
                                    Thread.sleep(20);
                    }   catch   (Exception   e)   {}


                    }
                      flushGraphics();
}
               
                private   void   input(){
int   keyState   =   getKeyStates();
                              //   System.out.println( "Connect   server   error ");
if((keyState   &   LEFT_PRESSED)   !=   0){    
                                        try{  
                                                System.out.println( "Connect   server   error ");
                                                String   url   =   "http://193.60.171.10/cgi-bin/camctrl.cgi?move=left ";
                                                HttpConnection   connection   =(HttpConnection)Connector.open(url);  
                                                InputStream   iStrm   =   connection.openInputStream();
                                                }catch   (IOException   ioe)   {}
                                  }   else   if   ((keyState   &   RIGHT_PRESSED)   !=   0){
                                            try{
                                                    String   url   =   "http://193.60.171.10/cgi-bin/camctrl.cgi?move=right ";
                                                    HttpConnection   connection   =(HttpConnection)Connector.open(url);
                                                    InputStream   iStrm   =   connection.openDataInputStream();
                                                    }catch   (IOException   ioe)   {}

}else   if((keyState   &   UP_PRESSED)   !=   0){
                                            try{


                                                    String   url   =   "http://193.60.171.10/cgi-bin/camctrl.cgi?move=up ";
                                                      HttpConnection   connection   =(HttpConnection)Connector.open(url);
                                                      InputStream   iStrm   =   connection.openInputStream();
                                                  }catch   (IOException   ioe)   {}

}else   if((keyState   &   DOWN_PRESSED)   !=   0){
                                            try{
                                                    String   url   =   "http://193.60.171.10/cgi-bin/camctrl.cgi?move=down ";
                                                    HttpConnection   connection   =(HttpConnection)Connector.open(url);
                                                    InputStream   iStrm   =   connection.openInputStream();
                                                }catch   (IOException   ioe)   {}
}
}
 
                  private   Image   getImage()   throws   IOException{
                        String   url= "http://193.60.171.10/cgi-bin/video.jpg ";      
                          HttpConnection   connection=(HttpConnection)Connector.open(url);
                          InputStream   iStrm=connection.openDataInputStream();
                          Image   im=null;
                          try{
                                        byte   imageData[];
                                          int   length=(int)connection.getLength();
                                          if(length!=-1){


                                          imageData=new   byte[length];
                                                  iStrm.read(imageData);
                                  }
                            else{
                                          ByteArrayOutputStream   bStrm=new   ByteArrayOutputStream();
                                          int   ch;
                                                while((ch=iStrm.read())!=-1){
                                                          bStrm.write(ch);
                                                  }
                                        imageData=bStrm.toByteArray();
                                        bStrm.close();
                                        }
                                im=Image.createImage(imageData,0,imageData.length);
                                  }
                          finally{
                                        if(iStrm!=null)
                                          iStrm.close();
                                          if(connection!=null)
                                            connection.close();
                          }
                                return(im==null?   null:im);
            }

}


PS:http://193.60.171.10/cgi-bin/camctrl.cgi?move=down
http://193.60.171.10/cgi-bin/camctrl.cgi?move=left


是控制远程摄像头的转向

[解决办法]
upppppppppppppppp
[解决办法]
这个我估计你的程序在按键之后就死锁了,所以没有响应
[解决办法]
最好获取摄像头图片的部分放在另外一个线程里,不然阻塞的话,很难响应按键

热点排行