CSDN博客

img zryStar

j2me智能手机实现远程监控室内操作(高级界面篇)

发表于2008/9/28 11:02:00  568人阅读

  1. import javax.microedition.lcdui.Alert;
  2. import javax.microedition.lcdui.AlertType;
  3. import javax.microedition.lcdui.Command;
  4. import javax.microedition.lcdui.CommandListener;
  5. import javax.microedition.lcdui.Displayable;
  6. import javax.microedition.lcdui.Form;
  7. import javax.microedition.lcdui.Image;
  8. import javax.microedition.lcdui.ImageItem;
  9. import javax.microedition.lcdui.Spacer;
  10. import java.io.IOException;
  11. import java.util.Timer;
  12. import sun.HttpConnection.HttpStringThread;
  13. import sun.HttpConnection.TaskInterface;
  14. import sun.dao.Control;
  15. /**
  16.  * @date 2008-08-22
  17.  * @author Administrator
  18.  * @function 监视操作:远程监视图片初始化界面
  19.  */
  20. public class VideoCatchForm extends Form implements CommandListener,
  21.         TaskInterface{
  22.     private Command Active_Start = new Command("开始",Command.ITEM,1);
  23.     private Command Active_End = new Command("停止",Command.ITEM,2);
  24.     private Command Black = new Command("返回",Command.BACK,3);
  25.     Alert alert;
  26.     TaskInterface ti;
  27.     
  28.     int count=0;
  29.     ImageItem item;
  30.     Image img11;    
  31.     Image img12;
  32.     String str = "";
  33.     NormalMIDlet midlet;
  34.     boolean ischeck;//验证码标识
  35.     public VideoCatchForm(NormalMIDlet Nmidlet) {
  36.         super("视频抓拍");
  37.         midlet = Nmidlet;       
  38.         try{            
  39.             img11 = Image.createImage("/png/11.png");   
  40.             img12 = Image.createImage("/png/12.png");
  41.         }catch(IOException ioe){
  42.             ioe.printStackTrace();
  43.         }
  44.         append(new Spacer(200,10));
  45.         item  = new ImageItem("",img11,ImageItem.LAYOUT_CENTER,"");         
  46.         append(item);       
  47.         addCommand(Active_Start);
  48.         addCommand(Active_End);
  49.         addCommand(Black);
  50.         setCommandListener(this);                       
  51.         ti = this;      
  52.     }   
  53.     public void commandAction(Command cmd, Displayable s) {
  54.         //开始监视
  55.         if(cmd == Active_Start){
  56.             if(midlet.ischeck == true){
  57.                 this.ischeck = true;
  58.                 str = cmd.getLabel();               
  59.                 item  = new ImageItem("",img12,ImageItem.LAYOUT_CENTER,"");
  60.                 this.set(1,item);
  61.                 String strUrl = "wap2.a-ihome.com/Video.aspx?TerminalNO="+Control.getTerminalNO()+"&AreaNO="+Control.getAreaNO()+"&Active=Start";
  62.                 HttpStringThread htt = new HttpStringThread(strUrl,ti);
  63.                 Thread th = new Thread(htt);
  64.                 th.start();
  65.             }else{
  66.                 this.ischeck = false;
  67.                 alert = new Alert("提示:""您输入的序列号或验证码有误"null,
  68.                         AlertType.ERROR);           
  69.                 midlet.display.setCurrent(alert);   
  70.             }
  71.         }
  72.         //停止操作
  73.         else if(cmd == Active_End){
  74.             if(midlet.ischeck == true){
  75.                 this.ischeck = true;
  76.                 str = cmd.getLabel();
  77.                 midlet.timer.cancel();          
  78.                 String strUrl = "wap2.a-ihome.com/Video.aspx?TerminalNO="+Control.getTerminalNO()+"&AreaNO="+Control.getAreaNO()+"&Active=End";
  79.                 HttpStringThread htt = new HttpStringThread(strUrl,ti);
  80.                 Thread th = new Thread(htt);
  81.                 th.start(); 
  82.             }else{
  83.                 ischeck = false;
  84.                 alert = new Alert("提示:""您输入的序列号或验证码有误"null,
  85.                         AlertType.ERROR);           
  86.                 midlet.display.setCurrent(alert);               
  87.             }
  88.         }
  89.         //返回
  90.         else if(cmd == Black){          
  91.             midlet.display.setCurrent(midlet.mainList);
  92.             midlet.timer.cancel();
  93.             item  = new ImageItem("",img11,ImageItem.LAYOUT_CENTER,"");
  94.             this.set(1,item);       
  95.         }
  96.     }   
  97.     //处理通信结果值
  98.     public void data(String result) {
  99.         if(result.equals("success")){
  100.             if(str.equals("开始")){
  101.                 midlet.timer = new Timer();
  102.                 midlet.timer.schedule(new VideoTimer(this,midlet), 02000);
  103.             }
  104.             else if(str.equals("停止")){
  105.                 item  = new ImageItem("",img11,ImageItem.LAYOUT_CENTER,"");
  106.                 this.set(1,item);               
  107.             }
  108.         }
  109.         else if(result.equals("error")||result.equals("fail")||result.equals("CommunicationError")){
  110.             Alert failer = new Alert("提示:""连接远程设备失败"null,
  111.                     AlertType.ERROR);           
  112.             midlet.display.setCurrent(failer);
  113.             item  = new ImageItem("",img11,ImageItem.LAYOUT_CENTER,"");
  114.             this.set(1, item);
  115.         }       
  116.     }
  117.     public void data(boolean result, String canvas) {
  118.         ;
  119.     }
  120.     public void data(String result, String canvas) {
  121.         ;
  122.     }
  123.     public void data(byte[] result) {
  124.         ;
  125.     }   
  126. }
  127. ////////////////////////////////////////////////////////////////////
  128. import java.util.TimerTask;
  129. import javax.microedition.lcdui.Graphics;
  130. import javax.microedition.lcdui.Image;
  131. import javax.microedition.lcdui.ImageItem;
  132. import sun.HttpConnection.HttpImageThread;
  133. import sun.HttpConnection.HttpStringThread;
  134. import sun.HttpConnection.TaskInterface;
  135. import sun.dao.Control;
  136. /**
  137.  * 
  138.  * @author Administrator
  139.  *  @function 图像抓取显示结果处理
  140.  */
  141. public class VideoTimer extends TimerTask implements TaskInterface {
  142.     VideoCatchForm cc;
  143.     NormalMIDlet midlet;
  144.     int count=0;
  145.     public VideoTimer(){
  146.         
  147.     }
  148.     public VideoTimer(VideoCatchForm cc,NormalMIDlet midlet){
  149.         this.cc=cc;
  150.         this.midlet = midlet;
  151.     }
  152.     //上传图片到网站
  153.     public void run() {
  154.         String resURL="wap2.a-ihome.com/VideoContent.aspx?TerminalNO="+Control.getTerminalNO()+"&AreaNO="+Control.getAreaNO();
  155.         HttpStringThread hst=new HttpStringThread(resURL,this);
  156.         Thread th=new Thread(hst);      
  157.         th.start();     
  158.         count++;
  159.         cc.count=count;     
  160.         if(this.count>20){
  161.             midlet.timer.cancel();
  162.             ImageItem item  = new ImageItem("",midlet.videocatch.img11,ImageItem.LAYOUT_CENTER,"");         
  163.             cc.set(1,item); 
  164.             midlet.display.setCurrent(cc);
  165.         }       
  166.     }   
  167.     public  final Image scale (Image srcImage, int newW, int newH) {  
  168.         int srcW = srcImage.getWidth();  
  169.         int srcH = srcImage.getHeight();  
  170.         //先做水平方向上的伸缩变换  
  171.         Image tmp = Image.createImage(newW, srcH);
  172.         Graphics g = tmp.getGraphics();  
  173.         for (int x = 0; x < newW; x++) {  
  174.                g.setClip(x, 01, srcH);  
  175.                //按比例放缩  
  176.                g.drawImage(srcImage,x-x*srcW/newW,0,Graphics.LEFT |Graphics.TOP);
  177.         }  
  178.         //再做垂直方向上的伸缩变换  
  179.         Image dst = Image.createImage(newW, newH);  
  180.         g = dst.getGraphics();  
  181.         for (int y = 0; y < newH; y++) {  
  182.                g.setClip(0, y, newW, 1);  
  183.                //按比例放缩  
  184.                g.drawImage(tmp,0,y-y*srcH/newH,Graphics.LEFT | Graphics.TOP);
  185.         }  
  186.         return dst;
  187.  }
  188.     public void data(String result) {   
  189.         if(!result.equals("")){
  190.             String strUrl = "wap2.a-ihome.com/Image/"+ControlAurine.getAreaNO()+"-"+ControlAurine.getTerminalNO()+"-Video.jpg";
  191.             HttpImageThread htt = new HttpImageThread(strUrl,this);     
  192.             Thread th = new Thread(htt);
  193.             th.start(); 
  194.         }       
  195.     }
  196.     public void data(boolean result, String canvas) {
  197.         ;       
  198.     }
  199.     public void data(String result, String canvas) {
  200.         ;       
  201.     }
  202.     public void data(byte[] result) {       
  203.         Image img=Image.createImage(result, 0, result.length);  
  204.         ImageItem item  = new ImageItem("",scale(img, 175150),ImageItem.LAYOUT_CENTER,"");            
  205.         if(img==null){
  206.             ;
  207.         }else{
  208.             cc.set(1,item);        
  209.         }       
  210.     }
  211. }

阅读全文
0 0

相关文章推荐

img
取 消
img