Wednesday, November 19, 2008

bloody mobapp

//import 3 packages: namely lcdui, midlet and rms
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;

public class Profile extends MIDlet implements CommandListener {

//declare a command variable
private Command exitCommand;
//...and display manager
private Display display;
//...and a variable for the Canvas child class
private OlympicsCanvas screen;
//constructor
public Profile()
{
//initialisation of display
display = Display.getDisplay(this);

//...and the command variable declared earlier
exitCommand = new Command("Exit", Command.STOP, 2);

//create the screen which is the object of the Canvas class
screen = new OlympicsCanvas();

//and add the command to this screen and set the command to listen to it
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}

//startApp()

public void startApp() throws MIDletStateChangeException {
//display the Canvas screen
display.setCurrent(screen);
}



//pauseApp()
public void pauseApp() { }

//destroyApp()
public void destroyApp(boolean unconditional) {
//close this midlet
}

//commandAction()
public void commandAction(Command c, Displayable s) {
//if it is to exit, call destroyApp()
if (c==exitCommand) {
destroyApp(false);
notifyDestroyed();
}}

}
//Child class of the Canvas class
class OlympicsCanvas extends Canvas {

//Declare the record store
private static RecordStore rs;
//...a byte[] variable
byte data[];
//...and a string variable called name
String name;





//paint()
public void paint(Graphics g) {

//clear screen
g.setColor(255,255,255); //white
g.fillRect(0,0,getWidth(), getHeight());

//draw face and fill it with yellow
g.setColor(255,255,0); //yellow
g.fillArc(50,50,150,150,0,360);

//draw the eyes and fill it with turquoise
g.setColor(64,224,208); //turquoise
g.fillArc(80,80,25,25,0,360); //left eye
g.fillArc(150,80,25,25,0,360); //right eye

//draw the nose and fill it with green
g.setColor(0,255,0); //green
g.fillArc(105,110,40,25,0,360);

//draw a red mouth
g.setColor(255,0,0); //red
g.drawArc(95,130,70,25,180,180);


//set the font color to black and set the font's style, type and size
g.setColor(0,0,0);
Font f=Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_ITALIC,Font.SIZE_LARGE);


try
{
//open the record store using same record store name as the "Login" class
rs = RecordStore.openRecordStore("friends",true);
}
catch (Exception e)
{
System.out.println("Error in opening record store " + e);
}


try {
//get the first record from the record store
data = rs.getRecord(1);
//convert it to a string
name = new String(data);
}
catch (Exception e){
System.out.println("Error in converting to string record store " + e);
}

//draw the string 1/5 from the base and right in the middle
g.drawString(name, getWidth()/2,getHeight()/5*4, g.BASELINE|g.HCENTER);


try {
//close the record store
rs.closeRecordStore();
}
catch (Exception e){
System.out.println("Error in closing record store " + e);
}
}
}

WTF IS THIS. i can't believe my mind is filled with all these bloody codes.
GOGOGOGOGOGOG, 25% here i am!

No comments: