viewimageui.java

来自「J2ME开发精解源代码已经过调试成功」· Java 代码 · 共 57 行

JAVA
57
字号
package com.j2medev.ch8.mmapi;

import javax.microedition.lcdui.*;

public class ViewImageUI extends Form implements CommandListener{
    
    private PowerCamera camera = null;
    private byte[] image = null;//
    private TextField title = new TextField("标题", "", 30, TextField.ANY);
    private Command saveCommand = new Command("保存",Command.OK, 1);
    private Command backCommand = new Command("返回",Command.BACK, 2);
    
    public ViewImageUI(PowerCamera pc,byte[] img) {
        super("照片");
        this.camera = pc;
        this.image = img;
        Image temp = null;
        //
        temp = Image.createImage(image, 0, image.length);
        this.append(temp);
        this.append(title);
        this.addCommand(saveCommand);
        this.addCommand(backCommand);
        this.setCommandListener(this);
        
    }
    public void backToPre(){
        camera.releasePlayer();//释放播放器
        camera.showCamera();//返回到摄像状态
        
    }
    
    public void showInfo(String message,AlertType type){
        Alert alert = new Alert("系统提示");
        alert.setString(message);
        alert.setTimeout(2000);
        alert.setType(type);
        Display.getDisplay(camera).setCurrent(alert, this);

    }
    
    
    public void commandAction(Command cmd,Displayable displayable){
        if(cmd == backCommand){
            this.backToPre();
            
        }else if(cmd == saveCommand){
            //
            String label = title.getString();
            Picture pic = new Picture(label, image);
            camera.savePicture(pic);
            showInfo("成功保存图片到我的相册", AlertType.CONFIRMATION);
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?