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

  1. import java.io.IOException;
  2. import java.util.TimerTask;
  3. import javax.microedition.lcdui.Graphics;
  4. import javax.microedition.lcdui.Image;
  5. import HttpConnection.HttpImageThread;
  6. import HttpConnection.HttpStringThread;
  7. /************************************************************
  8.  * Filename: VideoTimer.java
  9.  * @author Administrator
  10.  * Description: 监视模块的计时器,用于隔2秒获取一次访问图片,并显示到界面上
  11.  */
  12. public class VideoTimer extends TimerTask{
  13.     VideoCatch cc;
  14.     Aurine_Phone4N72 midlet;
  15.     public int count;
  16.     public VideoTimer(VideoCatch cc,Aurine_Phone4N72 midlet){
  17.         this.cc=cc;
  18.         this.midlet=midlet;
  19.         count=0;
  20.     }
  21.     public void setcount(){
  22.         this.count=0;
  23.     }
  24.     public void run() {
  25.         // TODO 自动生成方法存根
  26.         /*
  27.         String resURL="wap2.a-ihome.com/VideoContent.aspx?TerminalNO="+midlet.terno
  28.         +"&AreaNO="+midlet.areano;
  29.         HttpStringThread hst=new HttpStringThread(resURL,midlet,"VideoTimer");
  30.         Thread th=new Thread(hst);
  31.         th.start();
  32.         */
  33.         System.out.println(count);
  34.         count++;
  35.         String resURL="wap2.a-ihome.com/Image/"+midlet.areano+"-"+midlet.terno+"-Video.jpg";
  36.         HttpImageThread hit=new HttpImageThread(resURL,midlet,"VideoImage");
  37.         Thread th2=new Thread(hit);
  38.         th2.start();
  39.         
  40.         
  41.         /*
  42.         if(this.count>25){
  43.             
  44.             midlet.timer.cancel();
  45.             midlet.videotimer.cancel();
  46.             System.out.println("123");
  47.             try {
  48.                 midlet.videocatch.image=Image.createImage("/11.png");
  49.             } catch (IOException e) {
  50.                 // TODO 自动生成 catch 块
  51.                 e.printStackTrace();
  52.             }
  53.             //midlet.videocatch.addCommand(midlet.back);
  54.             midlet.videocatch.repaint();
  55.             midlet.videocatch.serviceRepaints();
  56.             
  57.             //midlet.gotoCanvas(midlet.videocatch);
  58.             //this.count=0;
  59.             System.out.println("123");
  60.             
  61.         }
  62.         */
  63.     }
  64.     /**  
  65.      * 图像放缩方法  
  66.      * @param srcImage 原始的Image对象  
  67.      * @param newW 放缩后的Image的宽度  
  68.      * @param newH 放缩后的Image的高度  
  69.      * @return 放缩后的Image对象  
  70.      */  
  71.     public  final Image scale (Image srcImage, int newW, int newH) {  
  72.            int srcW = srcImage.getWidth();  
  73.            int srcH = srcImage.getHeight();  
  74.            //先做水平方向上的伸缩变换  
  75.            Image tmp = Image.createImage(newW, srcH);
  76.            Graphics g = tmp.getGraphics();  
  77.            for (int x = 0; x < newW; x++) {  
  78.                   g.setClip(x, 01, srcH);  
  79.                   //按比例放缩  
  80.                   g.drawImage(srcImage,x-x*srcW/newW,0,Graphics.LEFT |Graphics.TOP);
  81.            }  
  82.            //再做垂直方向上的伸缩变换  
  83.            Image dst = Image.createImage(newW, newH);  
  84.            g = dst.getGraphics();  
  85.            for (int y = 0; y < newH; y++) {  
  86.                   g.setClip(0, y, newW, 1);  
  87.                   //按比例放缩  
  88.                   g.drawImage(tmp,0,y-y*srcH/newH,Graphics.LEFT | Graphics.TOP);
  89.            }  
  90.            return dst;
  91.     }
  92. }
  93. import java.io.IOException;
  94. import javax.microedition.lcdui.Canvas;
  95. import javax.microedition.lcdui.Font;
  96. import javax.microedition.lcdui.Graphics;
  97. import javax.microedition.lcdui.Image;
  98. /***************************************************************
  99.  * Filename: VideoCatch.java
  100.  * @author Administrator
  101.  * Description: 监视界面,用于开启、停止监视
  102.  */
  103. public class VideoCatch extends Canvas{
  104.     Image image;
  105.     Image img;
  106.     String result;
  107.     int issuccess;
  108.     int action;
  109.     boolean ischeck;
  110.     int count=0;
  111.     public VideoCatch(){
  112.         //      全屏显示
  113.         setFullScreenMode(true);
  114.         issuccess=0;
  115.         action=0;
  116.         ischeck=true;
  117.         try {
  118.             image=Image.createImage("/11.png");
  119.             img=Image.createImage("/10-3-1.png");
  120.         } catch (IOException e) {
  121.             // TODO 自动生成 catch 块
  122.             e.printStackTrace();
  123.         }
  124.     }
  125.     protected void paint(Graphics g) {
  126.         // TODO 自动生成方法存根
  127.         //      清理画布,底色转为白色。
  128.         g.setColor(255255255);
  129.         g.fillRect(00,this.getWidth() , this.getHeight());
  130.         Font font2=Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
  131.                 Font.SIZE_SMALL);
  132.         g.setFont(font2);
  133.         Font font=g.getFont();
  134.         //      画入顶图片
  135.         g.drawImage(img, this.getWidth()/215, Graphics.HCENTER|Graphics.VCENTER);
  136.         g.setColor(000);
  137.         if(image==null){
  138.             
  139.         }else{
  140.             g.drawImage(image,0,30,Graphics.LEFT|Graphics.TOP);
  141.         }
  142.         if(issuccess==-1){
  143.             if(action==1){
  144.                 g.setColor(255255255);
  145.                 g.fillRect(30this.getHeight()/2-40this.getWidth()-6070);
  146.                 g.setColor(000);
  147.                 g.drawRect(30this.getHeight()/2-40this.getWidth()-6070);
  148.                 g.setColor(8140201);
  149.                 g.fillRect(30this.getHeight()/2-40this.getWidth()-6020);
  150.                 g.setColor(000);
  151.                 g.drawString("错误"30+5this.getHeight()/2-40+10-(font.getHeight()>>1),
  152.                         Graphics.LEFT|Graphics.TOP);
  153.                 g.drawString("OK"this.getWidth()-16-30this.getHeight()/2-40+10-(font.getHeight()>>1),
  154.                         Graphics.LEFT|Graphics.TOP);
  155.                 g.drawString("开启监视失败。"this.getWidth()/2this.getHeight()/2-(font.getHeight()>>1),
  156.                         Graphics.HCENTER|Graphics.TOP);
  157.             }
  158.             else if(action==-1){
  159.                 g.setColor(255255255);
  160.                 g.fillRect(30this.getHeight()/2-40this.getWidth()-6070);
  161.                 g.setColor(000);
  162.                 g.drawRect(30this.getHeight()/2-40this.getWidth()-6070);
  163.                 g.setColor(8140201);
  164.                 g.fillRect(30this.getHeight()/2-40this.getWidth()-6020);
  165.                 g.setColor(000);
  166.                 g.drawString("错误"30+5this.getHeight()/2-40+10-(font.getHeight()>>1),
  167.                         Graphics.LEFT|Graphics.TOP);
  168.                 //亮蓝色框
  169.                 g.fillRect(this.getWidth()-48this.getHeight()/2-40+21616);
  170.                 g.setColor(000);
  171.                 g.drawString("OK"this.getWidth()-16-30this.getHeight()/2-40+10-(font.getHeight()>>1),
  172.                         Graphics.LEFT|Graphics.TOP);
  173.                 g.drawString("关闭监视失败。"this.getWidth()/2this.getHeight()/2-(font.getHeight()>>1),
  174.                         Graphics.HCENTER|Graphics.TOP);
  175.             }
  176.         }
  177.         if(ischeck==false){
  178.             g.setColor(255255255);
  179.             g.fillRect(30this.getHeight()/2-40this.getWidth()-6070);
  180.             g.setColor(000);
  181.             g.drawRect(30this.getHeight()/2-40this.getWidth()-6070);
  182.             g.setColor(8140201);
  183.             g.fillRect(30this.getHeight()/2-40this.getWidth()-6020);
  184.             g.setColor(000);
  185.             g.drawString("错误"30+5this.getHeight()/2-40+10-(font.getHeight()>>1), Graphics.LEFT|Graphics.TOP);
  186.             g.drawString("OK"this.getWidth()-16-30this.getHeight()/2-40+10-(font.getHeight()>>1),
  187.                     Graphics.LEFT|Graphics.TOP);
  188.             g.drawString("验证码错误。"this.getWidth()/2this.getHeight()/2-(font.getHeight()>>1),
  189.                     Graphics.HCENTER|Graphics.TOP);
  190.         }else{
  191.             
  192.         }
  193.     }
  194.     protected void keyPressed(int k){
  195.         if(k==-5){
  196.             if(ischeck==true){
  197.                 issuccess=0;
  198.                 action=0;
  199.                 try {
  200.                     image=Image.createImage("/11.png");
  201.                 } catch (IOException e) {
  202.                     // TODO 自动生成 catch 块
  203.                     e.printStackTrace();
  204.                 }
  205.                 repaint();
  206.                 this.serviceRepaints();
  207.             }
  208.             else {
  209.                 ischeck=true;
  210.                 repaint();
  211.                 serviceRepaints();
  212.             }
  213.         }
  214.     }
  215. }
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值