import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import java.io.*;
public class Rms extends Canvas //implements Runnable
{
public static String name ="afly";
private RecordStore rs=null;
private boolean empty=true;
public Rms ()
{
//new Thread(this).start();
xieru();
}
public void xieru(){
try{
rs=RecordStore.openRecordStore(name,true);
if(rs.getNumRecords()>0){
empty=false;
}else{
doa();
}
}catch(RecordStoreException e){}
}
public void doa(){
try {
init("bb.txt");
init("aa.png");
}catch(IOException e){
}catch(RecordStoreException ex){}
}
private void init(String str) throws IOException,RecordStoreException{
InputStream is=this.getClass().getResourceAsStream("/"+str);
if(is!=null){
ByteArrayOutputStream baos= new ByteArrayOutputStream();
byte[] data=new byte[1024];
int ch=0;
while((ch=is.read(data,0,data.length))!=-1){
baos.write(data,0,ch); }
byte[] a=baos.toByteArray();
rs.addRecord(a,0,a.length);
is.close();
baos.close();
} }
protected void paint(Graphics g){
g.setColor(0x00ffffff);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(0x00000000);
String aa=null;
try{
byte[] text=rs.getRecord(1);
aa=new String(text,"UTF-8");
}catch(RecordStoreException e){}catch(IOException ex){}
g.drawString(aa,0,0,0);
Image bb=null;
try{
byte[] img=rs.getRecord(2);
bb = Image.createImage(img,0,img.length);
}catch(RecordStoreException e){}
g.drawImage(bb,0,20,0);
}
}