j2me精解书籍代码j2me源代码很好的入门工具

源代码在线查看: powermodel.java

软件大小: 18837 K
上传用户: add505
关键词: j2me 书籍 代码 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				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;
				        }
				    }
				    
				    
				}
							

相关资源