×
Namespaces

Variants
Actions

How to create an LCDUI Splash Screen

From Nokia Developer Wiki
Jump to: navigation, search

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.

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 ExampleTested with
Devices(s): X3-02, E7-00, Asha 305
CompatibilityArticle
Created: skalogir (02 Nov 2011)
Reviewed: skalogir (02 Nov 2011)
Last edited: hamishwillee (26 Jul 2013)
This page was last modified on 26 July 2013, at 07:33.
90 page views in the last 30 days.
×