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

📄 powermodel.java

📁 <j2me 开发精解> 詹建光著 里所有的源码。对J2me的开发相当有帮助
💻 JAVA
字号:
package com.j2medev.ch8.mmapi;

import java.io.*;
import javax.microedition.lcdui.AlertType;
import javax.microedition.rms.*;

public class PowerModel {
    
    private RecordStore rs = null;
    private PowerCamera pc = null;
    
    public PowerModel(PowerCamera pc) {
        this.pc = pc;
        try{
            rs = RecordStore.openRecordStore("camera",true);
        }catch(RecordStoreException ex){
            ex.printStackTrace();
        }
    }
    public void savePicture(Picture pic){
        try{
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos);
            pic.serialize(dos);
            dos.close();
            byte[] data = baos.toByteArray();
            rs.addRecord(data, 0, data.length);
        }catch(IOException ex){
            pc.showInfo(ex.toString(), AlertType.ERROR);
        }catch(RecordStoreException ex){
            pc.showInfo(ex.toString(), AlertType.ERROR);
        }
    }
    
    public Picture[] getAllPicture(){
        try{
            int num = rs.getNumRecords();
            if(num == 0){
                return null;
            }else{
                RecordEnumeration re = rs.enumerateRecords(null,null,false);
                int length = re.numRecords();
                Picture[] pic = new Picture[length];
                int i = 0;
                while(re.hasNextElement()){
                    byte[] data = re.nextRecord();
                    ByteArrayInputStream bais = new ByteArrayInputStream(data);
                    DataInputStream dis = new DataInputStream(bais);
                    pic[i] = Picture.deserialize(dis);
                    i++;
                    dis.close();
                }
                return pic;
            }
        }catch(IOException ex){
            pc.showInfo(ex.toString(), AlertType.ERROR);
        } catch(RecordStoreException ex){
            pc.showInfo(ex.toString(), AlertType.ERROR);
        }
        return null;
    }
    public static String isVideoCapture(){
        return System.getProperty("supports.video.capture");
    }
    public void release(){
        if(rs != null){
            try{
                rs.closeRecordStore();
            }catch(RecordStoreException ex){
                //不做处理
            }
            rs = null;
        }
    }
    
    
}

⌨️ 快捷键说明

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