Hi every one i would like to display the record store data in the Gamecanvas but i am not able to do so please help.
File on 1
import javax.microedition.rms.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
public class a
extends MIDlet
{
private Display display;
String inputString;
rms test;
public RecordStore recordstore;
public a()
{
test();
}
public void startApp()
{
display = Display.getDisplay(this);
test=new rms(this);
test.start();
display.setCurrent(test);
}
public void pauseApp()
{
}
public void destroyApp( boolean unconditional )
{
}
public void test()
{
try
{
recordstore = RecordStore.openRecordStore(
"Scores", true );
}
catch (Exception error)
{
}
try
{
byte[] outputRecord;
String outputString = "AAkash";
int outputInteger = 15;
boolean outputBoolean = true;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DataOutputStream outputDataStream =new DataOutputStream(outputStream);
outputDataStream.writeUTF(outputString);
outputDataStream.writeBoolean(outputBoolean);
outputDataStream.writeInt(outputInteger);
outputDataStream.flush();
outputRecord = outputStream.toByteArray();
recordstore.addRecord(outputRecord, 0, outputRecord.length);
outputStream.reset();
outputStream.close();
outputDataStream.close();
}
catch ( Exception error)
{
}
try
{
int inputInteger = 0;
boolean inputBoolean = false;
byte[] byteInputData = new byte[100];
ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData);
DataInputStream inputDataStream =new DataInputStream(inputStream);
for (int x = 1; x <= recordstore.getNumRecords(); x++)
{
recordstore.getRecord(x, byteInputData, 0);
inputString = inputDataStream.readUTF();
inputBoolean = inputDataStream.readBoolean();
inputInteger = inputDataStream.readInt();
inputStream.reset();
}
inputStream.close();
inputDataStream.close();
System.out.println(inputString + inputBoolean);
}
catch (Exception error)
{
}
try
{
}
catch (Exception error)
{
}
}
}
File no 2 Th Gane Canvas
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Deepz
*/
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class rms extends GameCanvas implements Runnable {
private boolean isPlay;
private long delay;
private int currentX, currentY;
public a parent;
private int width;
private int height;
public rms(a parent ) {
super(true);
width = getWidth();
height = getHeight();
currentX = width / 2;
currentY = height / 2;
delay = 20;
}
public void start() {
isPlay = true;
Thread t = new Thread(this);
t.start();
}
public void stop() { isPlay = false; }
public void run() {
Graphics g = getGraphics();
while (isPlay == true) {
input();
drawScreen(g);
try { Thread.sleep(delay); }
catch (InterruptedException ie) {}
}
}
private void input() {
}
private void drawScreen(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x0000ff);
try{
g.drawString(parent.inputString,currentX,currentY,Graphics.TOP|Graphics.LEFT);
}
catch(Exception e)
{
}
}
}
