I am developing a splash screen for my Java ME application built using NetBeans 6.8. I have completed the coding part. When I try to run it in Portrait mode, it works as I wanted but not in Landscape mode. I am getting blank screen. Is there anyone who can provide me a tip to get it working?
Here is my code:
Code:public class MySplashScreen extends SplashScreen { private msnIM theMsnIM; public MySplashScreen (Display show, msnIM theMsnIM) throws IllegalArgumentException { super(show); this.theMsnIM = theMsnIM; } protected void sizeChanged(int w, int h) { if(theMsnIM == null) { System.out.println("the midlet is null!."); return; } if(!theMsnIM.isMidletInitialized()) { System.out.println("the midlet is not initialized yet."); return; } if(w > h) this.theMsnIM.updateSplashScreenImage(false); else this.theMsnIM.updateSplashScreenImage(true); super.sizeChanged(w, h); //repaint(); } } public class msnIM extends MIDlet implements CommandListener { private boolean midletPaused = false; private boolean midletInitialized = false; private MySplashScreen splashScreen; private Form form; private StringItem stringItem; private Command exitCommand; private Image imageSPPortrait; private Image imageSPLandscape; private void initialize() { try { imageSPLandscape = Image.createImage("/com/akezamedia/msnim/image.png"); imageSPPortrait = Image.createImage("/com/akezamedia/msnim/image.png"); } catch (java.io.IOException e) { e.printStackTrace(); System.out.println(e.getMessage() + " :: " + e.getClass()); } } public void startMIDlet() { initialize(); midletInitialized = true; switchDisplayable(null, getSplashScreen()); } public boolean isMidletInitialized() { return midletInitialized; } public void resumeMIDlet() { } public void switchDisplayable(Alert alert, Displayable nextDisplayable) { Display show = getDisplay(); if (alert == null) { show.setCurrent(nextDisplayable); } else { show.setCurrent(alert, nextDisplayable); } } public void commandAction(Command command, Displayable displayable) { // write pre-action user code here if (displayable == form) { if (command == exitCommand) { // write pre-action user code here exitMIDlet(); // write post-action user code here } } else if (displayable == splashScreen) { if (command == MySplashScreen.DISMISS_COMMAND) { // write pre-action user code here switchDisplayable(null, getForm()); // write post-action user code here } } // write post-action user code here } public MySplashScreen getSplashScreen() { if (splashScreen == null) { // write pre-init user code here splashScreen = new MySplashScreen (getDisplay(), this); splashScreen.setTitle("MsnIM 1.0"); splashScreen.setCommandListener(this); splashScreen.setFullScreenMode(true); //splashScreen.setImage(this.getImageSPLandscape()); splashScreen.setImage(this.imageSPPortrait); splashScreen.setTimeout(10000); splashScreen.setAllowTimeoutInterrupt(false); // write post-init user code here } return splashScreen; } public Form getForm() { if (form == null) { // write pre-init user code here form = new Form("Welcome to MsnIM 1.0", new Item[] { getStringItem() }); form.addCommand(getExitCommand()); form.setCommandListener(this); // write post-init user code here } return form; } public void updateSplashScreenImage(boolean portrait) { System.out.println("portrait: " + portrait); if(portrait) { //Image m = getImageSPPortrait(); System.out.println("image is null?= " + this.imageSPPortrait==null); //splashScreen.setImage(getImageSPPortrait()); splashScreen.setImage(this.imageSPPortrait); } else { //Image m = getImageSPLandscape(); System.out.println("image is null?= " + this.imageSPLandscape==null); //splashScreen.setImage(getImageSPLandscape()); splashScreen.setImage(this.imageSPLandscape); } } public Image getImageSPPortrait() { if (imageSPPortrait == null) { // write pre-init user code here try { imageSPPortrait = Image.createImage("/com/akezamedia/msnim/msnIMDefault_n97.png"); } catch (java.io.IOException e) { e.printStackTrace(); System.out.println(e.getMessage() + " :: " + e.getClass()); } // write post-init user code here } return imageSPPortrait; } public Image getImageSPLandscape() { if (imageSPLandscape == null) { // write pre-init user code here try { imageSPLandscape = Image.createImage("/com/akezamedia/msnim/msnIMDefault_n97L.png"); } catch (java.io.IOException e) { e.printStackTrace(); System.out.println(e.getMessage() + " :: " + e.getClass()); } // write post-init user code here } return imageSPLandscape; } public Command getExitCommand() { if (exitCommand == null) { // write pre-init user code here exitCommand = new Command("Exit", Command.EXIT, 0); // write post-init user code here } return exitCommand; } public StringItem getStringItem() { if (stringItem == null) { // write pre-init user code here stringItem = new StringItem("", "Testing here"); // write post-init user code here } return stringItem; } public Display getDisplay () { return Display.getDisplay(this); } public void exitMIDlet() { switchDisplayable (null, null); destroyApp(true); notifyDestroyed(); } public void startApp() { if (midletPaused) { resumeMIDlet (); } else { initialize (); startMIDlet (); } midletPaused = false; } public void pauseApp() { midletPaused = true; } public void destroyApp(boolean unconditional) { } }
Bookmarks