J2ME开发精解源代码已经过调试成功

源代码在线查看: powermodel.java

软件大小: 3115 K
上传用户: hslhsl123
关键词: 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;
				        }
				    }
				    
				    
				}
							

相关资源