How to create an LCDUI Splash Screen
This article explains how to create a splash screen that displays an image for a few seconds and then disappears. Additional functionality is added so that the user can skip the splash screen when any key is pressed.
See Also
- How to create a Splash Screen in eSWT
- How to make video splashscreen in Java ME
- How to create an LCDUI Splash Screen
- Alert based splashscreen in Java ME
- Full screen Canvas Splash screen in Java ME
Contents |
Implementation considerations
The image type selected for the splash screen should be supported by the device. A list of supported image types for a given device is available here
The image selected in this example, can be found in the attached source file. In order for this example to work properly, the image should be copied to the project's resource files.
In order to disable the on-screen keypad, the Nokia-MIDlet-On-Screen-Keypad JAD attribute should be set to no, in the file descriptor.
The SplashScreenMidlet.java midlet
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class SplashScreenMidlet extends MIDlet implements CommandListener {
Form f;
Command exitCommand;
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException {
}
protected void pauseApp() {
}
protected void startApp() throws MIDletStateChangeException {
Display.getDisplay(this).setCurrent(new SplashScreen(this));
}
//After the splash screen is displayed, code is resumed from here
void splashScreenDone()
{
Form f;
exitCommand=new Command("Exit",Command.EXIT,0);
f=new Form("");
f.append("Splash Screen loading completed");
f.addCommand(exitCommand);
f.setCommandListener(this);
Display.getDisplay(this).setCurrent(f);
}
static Image createImage(String filename)
{
Image image = null;
try
{
image = Image.createImage(filename);
}
catch (java.io.IOException ex)
{
System.out.println(ex.getMessage());ex.printStackTrace();
}
return image;
}
public void commandAction(Command cmd, Displayable dis) {
if(cmd==exitCommand)
{
notifyDestroyed();
}
}
}
The SplashScreen.java class
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class SplashScreen extends Canvas implements Runnable
{
private final SplashScreenMidlet midlet;
private Image splashImage;
private volatile boolean dismissed = false;
SplashScreen(SplashScreenMidlet midlet)
{
this.midlet = midlet;
setFullScreenMode(true);
splashImage = SplashScreenMidlet.createImage("/logoJava.png");
new Thread(this).start();
}
public void run()
{
synchronized(this)
{
try
{
wait(3000L); // 3 seconds
}
catch (InterruptedException e)
{
// can't happen in MIDP: no Thread.interrupt method
}
dismiss();
}
}
public void paint(Graphics g)
{
int width = getWidth();
int height = getHeight();
g.setColor(0x00FFFFFF); // white
g.fillRect(0, 0, width, height);
g.setColor(0x00FF0000); // red
g.drawRect(1, 1, width-3, height-3); // red border one pixel from edge
if (splashImage != null)
{
g.drawImage(splashImage,
width/2,
height/2,
Graphics.VCENTER | Graphics.HCENTER);
splashImage = null;
}
}
public synchronized void keyPressed(int keyCode)
{
dismiss();
}
private void dismiss()
{
if (!dismissed)
{
dismissed = true;
midlet.splashScreenDone();
}
}
}
Resources
The source files, including the resource image file, are available here: File:SplashScreenMidlet source.zip
The binary files are available here: File:SplashScreenMidlet binaries.zip
See also
How to disable the On-screen Keypad
Article Metadata
Code Example
Tested with
Compatibility
Article


(no comments yet)