⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexmidlet.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
package com.j2medev.chapter3;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class IndexMIDlet extends MIDlet implements CommandListener{
    
    private Display display = null;
    //初始化RecordEngine
    private RecordEngine engine = new RecordEngine(true);
    private List list = new List("rms",List.IMPLICIT);
    private Form form = new Form("Image Index");
    private Command backCommand = new Command("back",Command.BACK,1);
    private Command exitCommand = new Command("Exit",Command.EXIT,1);
    private Command deleteCommand = new Command("delete",Command.OK,2);
    private Command addCommand = new Command("add",Command.OK,3);
    
    public void startApp() {
        if(display == null){
            display = Display.getDisplay(this);
            String[] names = engine.getAllPictureName();
            if(names != null){
                for(int i = 0;i<names.length;i++){
                    list.append(names[i],null);
                }
            }
            form.addCommand(backCommand);
            form.setCommandListener(this);
            list.addCommand(deleteCommand);
            list.addCommand(addCommand);
            list.addCommand(exitCommand);
            list.setCommandListener(this);
            display.setCurrent(list);
        }
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void commandAction(Command cmd,Displayable displayable){
        if(cmd == List.SELECT_COMMAND){
            String name = list.getString(list.getSelectedIndex());
            //读取Picture
            Picture pic = engine.getPictureByName(name);
            form.deleteAll();
            Image img = Image.createImage(pic.img,0,pic.img.length);
            form.append(pic.name);
            form.append(img);
            display.setCurrent(form);
        }else if(cmd == backCommand){
            display.setCurrent(list);
        }else if(cmd == addCommand){
            //添加一个Picture
            engine.writeData(1);
            list.deleteAll();
            String[] names = engine.getAllPictureName();
            if(names != null){
                for(int i = 0;i<names.length;i++){
                    list.append(names[i],null);
                }
            }
        }else if(cmd == deleteCommand){
            //删除一个Picture
            String name = list.getString(list.getSelectedIndex());
            try{
                engine.deletePicture(name);
                list.delete(list.getSelectedIndex());
                display.setCurrent(list);
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }else if(cmd == exitCommand){
            destroyApp(false);
            notifyDestroyed();
        }
    }
}

⌨️ 快捷键说明

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