- import java.io.IOException;
- import java.util.TimerTask;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- import HttpConnection.HttpImageThread;
- import HttpConnection.HttpStringThread;
- /************************************************************
- * Filename: VideoTimer.java
- * @author Administrator
- * Description: 监视模块的计时器,用于隔2秒获取一次访问图片,并显示到界面上
- */
- public class VideoTimer extends TimerTask{
- VideoCatch cc;
- Aurine_Phone4N72 midlet;
- public int count;
- public VideoTimer(VideoCatch cc,Aurine_Phone4N72 midlet){
- this.cc=cc;
- this.midlet=midlet;
- count=0;
- }
- public void setcount(){
- this.count=0;
- }
- public void run() {
- // TODO 自动生成方法存根
- /*
- String resURL="wap2.a-ihome.com/VideoContent.aspx?TerminalNO="+midlet.terno
- +"&AreaNO="+midlet.areano;
- HttpStringThread hst=new HttpStringThread(resURL,midlet,"VideoTimer");
- Thread th=new Thread(hst);
- th.start();
- */
- System.out.println(count);
- count++;
- String resURL="wap2.a-ihome.com/Image/"+midlet.areano+"-"+midlet.terno+"-Video.jpg";
- HttpImageThread hit=new HttpImageThread(resURL,midlet,"VideoImage");
- Thread th2=new Thread(hit);
- th2.start();
- /*
- if(this.count>25){
- midlet.timer.cancel();
- midlet.videotimer.cancel();
- System.out.println("123");
- try {
- midlet.videocatch.image=Image.createImage("/11.png");
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- //midlet.videocatch.addCommand(midlet.back);
- midlet.videocatch.repaint();
- midlet.videocatch.serviceRepaints();
- //midlet.gotoCanvas(midlet.videocatch);
- //this.count=0;
- System.out.println("123");
- }
- */
- }
- /**
- * 图像放缩方法
- * @param srcImage 原始的Image对象
- * @param newW 放缩后的Image的宽度
- * @param newH 放缩后的Image的高度
- * @return 放缩后的Image对象
- */
- public final Image scale (Image srcImage, int newW, int newH) {
- int srcW = srcImage.getWidth();
- int srcH = srcImage.getHeight();
- //先做水平方向上的伸缩变换
- Image tmp = Image.createImage(newW, srcH);
- Graphics g = tmp.getGraphics();
- for (int x = 0; x < newW; x++) {
- g.setClip(x, 0, 1, srcH);
- //按比例放缩
- g.drawImage(srcImage,x-x*srcW/newW,0,Graphics.LEFT |Graphics.TOP);
- }
- //再做垂直方向上的伸缩变换
- Image dst = Image.createImage(newW, newH);
- g = dst.getGraphics();
- for (int y = 0; y < newH; y++) {
- g.setClip(0, y, newW, 1);
- //按比例放缩
- g.drawImage(tmp,0,y-y*srcH/newH,Graphics.LEFT | Graphics.TOP);
- }
- return dst;
- }
- }
- import java.io.IOException;
- import javax.microedition.lcdui.Canvas;
- import javax.microedition.lcdui.Font;
- import javax.microedition.lcdui.Graphics;
- import javax.microedition.lcdui.Image;
- /***************************************************************
- * Filename: VideoCatch.java
- * @author Administrator
- * Description: 监视界面,用于开启、停止监视
- */
- public class VideoCatch extends Canvas{
- Image image;
- Image img;
- String result;
- int issuccess;
- int action;
- boolean ischeck;
- int count=0;
- public VideoCatch(){
- // 全屏显示
- setFullScreenMode(true);
- issuccess=0;
- action=0;
- ischeck=true;
- try {
- image=Image.createImage("/11.png");
- img=Image.createImage("/10-3-1.png");
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- protected void paint(Graphics g) {
- // TODO 自动生成方法存根
- // 清理画布,底色转为白色。
- g.setColor(255, 255, 255);
- g.fillRect(0, 0,this.getWidth() , this.getHeight());
- Font font2=Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
- Font.SIZE_SMALL);
- g.setFont(font2);
- Font font=g.getFont();
- // 画入顶图片
- g.drawImage(img, this.getWidth()/2, 15, Graphics.HCENTER|Graphics.VCENTER);
- g.setColor(0, 0, 0);
- if(image==null){
- }else{
- g.drawImage(image,0,30,Graphics.LEFT|Graphics.TOP);
- }
- if(issuccess==-1){
- if(action==1){
- g.setColor(255, 255, 255);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(0, 0, 0);
- g.drawRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(8, 140, 201);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 20);
- g.setColor(0, 0, 0);
- g.drawString("错误", 30+5, this.getHeight()/2-40+10-(font.getHeight()>>1),
- Graphics.LEFT|Graphics.TOP);
- g.drawString("OK", this.getWidth()-16-30, this.getHeight()/2-40+10-(font.getHeight()>>1),
- Graphics.LEFT|Graphics.TOP);
- g.drawString("开启监视失败。", this.getWidth()/2, this.getHeight()/2-(font.getHeight()>>1),
- Graphics.HCENTER|Graphics.TOP);
- }
- else if(action==-1){
- g.setColor(255, 255, 255);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(0, 0, 0);
- g.drawRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(8, 140, 201);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 20);
- g.setColor(0, 0, 0);
- g.drawString("错误", 30+5, this.getHeight()/2-40+10-(font.getHeight()>>1),
- Graphics.LEFT|Graphics.TOP);
- //亮蓝色框
- g.fillRect(this.getWidth()-48, this.getHeight()/2-40+2, 16, 16);
- g.setColor(0, 0, 0);
- g.drawString("OK", this.getWidth()-16-30, this.getHeight()/2-40+10-(font.getHeight()>>1),
- Graphics.LEFT|Graphics.TOP);
- g.drawString("关闭监视失败。", this.getWidth()/2, this.getHeight()/2-(font.getHeight()>>1),
- Graphics.HCENTER|Graphics.TOP);
- }
- }
- if(ischeck==false){
- g.setColor(255, 255, 255);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(0, 0, 0);
- g.drawRect(30, this.getHeight()/2-40, this.getWidth()-60, 70);
- g.setColor(8, 140, 201);
- g.fillRect(30, this.getHeight()/2-40, this.getWidth()-60, 20);
- g.setColor(0, 0, 0);
- g.drawString("错误", 30+5, this.getHeight()/2-40+10-(font.getHeight()>>1), Graphics.LEFT|Graphics.TOP);
- g.drawString("OK", this.getWidth()-16-30, this.getHeight()/2-40+10-(font.getHeight()>>1),
- Graphics.LEFT|Graphics.TOP);
- g.drawString("验证码错误。", this.getWidth()/2, this.getHeight()/2-(font.getHeight()>>1),
- Graphics.HCENTER|Graphics.TOP);
- }else{
- }
- }
- protected void keyPressed(int k){
- if(k==-5){
- if(ischeck==true){
- issuccess=0;
- action=0;
- try {
- image=Image.createImage("/11.png");
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- repaint();
- this.serviceRepaints();
- }
- else {
- ischeck=true;
- repaint();
- serviceRepaints();
- }
- }
- }
- }