2009-09-14

How to create a splash screen in J2ME

import java.io.IOException;
import javax.microedition.lcdui.*;

public class MIDPCanvas extends Canvas implements CommandListener {

public MIDPCanvas() {
try {
// Set up this canvas to listen to command events
setCommandListener(this);
// Add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
} catch(Exception e) {
e.printStackTrace();
}
}

/**
* paint
*/
public void paint(Graphics g) {
//Set the screen to Fullscreen
setFullScreenMode(true);
g.setColor(0x00FFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
Image img=null;
try {
//Set the picture
img = Image.createImage("/picture/Untitled-1.png");
} catch (IOException ex) {
ex.printStackTrace();
}
g.drawImage(img, getWidth() / 2, getHeight() / 2 - 5, 3);
try{
//Set the loading time here. I set it as 1 second (1000 milliseconds)
Thread.sleep(1000);
}
catch(Exception e){
System.out.println("Error");
}
}

/**
* Called when a key is pressed.
*/
protected void keyPressed(int keyCode) {
}

/**
* Called when a key is released.
*/
protected void keyReleased(int keyCode) {
}

/**
* Called when a key is repeated (held down).
*/
protected void keyRepeated(int keyCode) {
}

/**
* Called when the pointer is dragged.
*/
protected void pointerDragged(int x, int y) {
}

/**
* Called when the pointer is pressed.
*/
protected void pointerPressed(int x, int y) {
}

/**
* Called when the pointer is released.
*/
protected void pointerReleased(int x, int y) {
}

/**
* Called when action should be handled
*/
public void commandAction(Command command, Displayable displayable) {
}

}

1 comment:

Web Development Company India said...

It is very essential coding method to create the splash screen to the developers.I really glad to this blog for giving this useful information.
Web Development Company India | Web Design Company India