J2ME Polish 1.3: InitializerSplashScreen
May 16, 2006 · Print This Article
J2ME Polish contains a neat splash screen convenience feature in version 1.3, currently in beta. Implementing the ApplicationInitializer interface, and calling the InitializerSplashScreen with the appropriate arguments is all you need to do to create your splash screen.
Polish then creates a background thread, calls your initialization code in that thread, and creates and displays your splash screen. You can specify a canvas background color, a splash screen image, message text, and message color. If you choose to include message text, when your initialization code returns, the message is displayed to the user, and a new displayable is served after a click, similar to the popular interaction mode in many mobile games. A null message text will indicate to Polish that the next displayable should immediately be shown to the user.
Import the Polish splash package:
import de.enough.polish.ui.splash.*;
Use preprocessing to determine if ApplicationInitializer is defined in build.xml. You do not want to define the preprocessing variable in build.xml and implement the interface.
public class AmazonController extends MIDlet
//#if !polish.classes.ApplicationInitializer:defined
implements ApplicationInitializer, CommandListener {
//#else
implements CommandListener {
//#endif
You will place all of your initialization code in the initApp() method, rather than in the constructor or in startApp(). Your initApp() method must return a Displayable (the screen to be displayed when the thread completes its business).
public Displayable initApp() {
mainMenu = new MainMenu(this);
/** @todo add your initialization code */
return mainMenu;
}
In startApp(), call InitializerSplashScreen with the appropriate arguments: Displayable screenToShowOnLoad, Image splashImage, int backgroundColor, String messageToDisplayAfterLoad, ApplicationInitializer midletImplementingInitializerInterface).
try {
Image splashImage = Image.createImage(”/splash.png”);
InitializerSplashScreen splashScreen = new InitializerSplashScreen(display, splashImage, 0xFFFFFF, null, 0×359AA8, this);
display.setCurrent(splashScreen);
} catch (IOException e) {
//#debug error
System.out.println(”Unable to load splash image.” + e);
}
Pretty slick. Nothing earth shattering, but just another way that J2ME Polish can save you some time developing mobile applications. The best part is that, like most Polish classes, the splash screen will function on a large number of MIDP implementations without requiring any tuning on your part.
Tags: J2ME, Java ME, J2ME Polish, mobile software, mobile development




I got the information regarding polish image uploading in splashscreen.
The example above is similar to others I’ve read on the net but all have the same problem. The splashscreen is displayed until a key is pressed.
Is there anyway to set a timeout so the application starts even if a key isn’t pressed?
Also is it possible to load multiple splashscreens (one after the other)?
Thanks in advance
Hey r00nster, you might be using a buggy build, or perhaps your initApp() method is code properly. This should work just fine without requiring a key press.
1) If you’re using an old Polish build, I’d recommend upgrading to the 2.0 Preview, not the release candidate.
2) Make sure your initApp() method returns a Displayable.
3) If you think it is, spit out some debug statements to verify that startup is working as you expect it should.
4) Multiple splash screens? Of course, but you have to code the logic yourself. What I do is create my own SplashScreen class based off of Polish’s, and I add setStatusMessage() and setStatusImage() methods to it. I then call these method from within initApp() to announce progress. On faster phones, it’s a moot point because there’s little time to repaint, but on slower phones, it works well.
Good luck!
That should be “coded improperly.”
Ok downloaded the latest version and it all burst into life (Many thanks) but I don’t fully understand your explanation of the multiple splashscreens scenario. Creating a seperate class etc. but I don’t see how you change the InitializerSplashScreen image or text within initapp as when that thread is running how do you access the image or message properties of the splashscreen to change them? Obviously I’m missing something here so bear with me.
Example code would be much appreciated.
All you need to do is repaint(). So do something like this:
1) Create your own SplashScreen class. Give it member variables: Image splashImage, String splashMessage. Add setters for splashImage and splashMessage and call repaint() from them.
2) In the paint() method of your SplashScreen class, the image and message are drawn with g.drawImage() and g.drawString().
3) From your midlet, create the splash screen and hold a reference to it. In initApp(), do your initialization work and periodically call splash.setMessage() and splash.setImage() with your message updates or image changes.
Make sense?
Shaun (joefission)
hi
ukhtazwh5spnex31
good luck
hi
ukhtazwh5spnex31
good luck