showphoto.java

来自「J2ME程序设计实例教程的源码」· Java 代码 · 共 50 行

JAVA
50
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class ShowPhoto extends MIDlet implements CommandListener {
    Image imgDog = null;
    Image imgDinosaur = null;
    
    //构造方法
    public ShowPhoto() {
        //
    }
      
    public void startApp() {
        Form form = new Form("浏览图片");
        try {
            imgDog = Image.createImage("/Dog.png");
            imgDinosaur = Image.createImage("/Dinosaur.png");
            form.append(imgDog);
            form.append(imgDinosaur);
        }
        catch(IOException ioe){
            form.append(new StringItem("错误!","图片不存在"));
        }
        
        Command cmdExit = new Command("退出", Command.EXIT, 0);
        form.addCommand(cmdExit);
        form.setCommandListener(this);
    
        Display display = Display.getDisplay(this);
        display.setCurrent(form);
    }
      
    public void pauseApp() {
        imgDog = null;
        imgDinosaur = null;
    }
    
    public void destroyApp(boolean undicational) {
        //
    }
    
    //如果用户触发“退出”命令,系统将自动调用这个方法
    public void commandAction(Command cmd, Displayable d) {
        if(cmd.getCommandType() == Command.EXIT){
            notifyDestroyed();
        }
    }
}

⌨️ 快捷键说明

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