JME(J2ME) Splash Screen

peter_budo peter_budo is offline Offline Oct 3rd, 2009, 2:03 pm |
5
Here is simple example of static image to be displayed as logo on the start-up/splash screen.
This can be improved by creating animation out of series of images or use of flash file through Project Capuchin library.
As for location of image file this was placed in new folder called "res" as resources. The folder is on same level as "myProject" folder that holds Java classes. If you decide to have "res" folder placed inside "myProject" folder then image path will be /myProject/res/IMAGE_NAME ProjectMIDlet.java
  1. package myProject;
  2.  
  3. /**
  4.  * Created by IntelliJ IDEA.
  5.  * User: Peter
  6.  * URL: [url]http://www.peterscorner.co.uk[/url]
  7.  * Date: 02-Oct-2009
  8.  * Time: 17:40:55
  9.  */
  10.  
  11. import javax.microedition.midlet.MIDlet;
  12. import javax.microedition.lcdui.Display;
  13.  
  14. import myProject.screens.SplashScreen;
  15.  
  16. public class ProjectMIDlet extends MIDlet{
  17.  
  18. public String ti;
  19. public String entrydate;
  20. public String result;
  21.  
  22. private Display display;
  23.  
  24.  
  25. public ProjectMIDlet() {}
  26.  
  27. public void startApp() {
  28. if(display == null){
  29. display = Display.getDisplay(this);
  30. }
  31. display.setCurrent(new SplashScreen(this));
  32.  
  33. }
  34.  
  35. public void pauseApp() {}
  36.  
  37. public void destroyApp(boolean unconditional) {}
  38.  
  39. }

NextScreen.java
  1. package myProject.screens;
  2.  
  3. /**
  4.  * Created by IntelliJ IDEA.
  5.  * User: Peter
  6.  * URL: [url]http://www.peterscorner.co.uk[/url]
  7.  * Date: 02-Oct-2009
  8.  * Time: 17:56:08
  9.  */
  10. import javax.microedition.lcdui.Command;
  11. import javax.microedition.lcdui.CommandListener;
  12. import javax.microedition.lcdui.Displayable;
  13. import javax.microedition.lcdui.Form;
  14. import javax.microedition.lcdui.StringItem;
  15.  
  16. import myProject.ProjectMIDlet;
  17.  
  18. public class NextScreen extends Form implements CommandListener{
  19.  
  20. private ProjectMIDlet projectMidlet;
  21.  
  22. public NextScreen(ProjectMIDlet projectMidlet){
  23. super("Next Screen");
  24. this.projectMidlet = projectMidlet;
  25. init();
  26. }
  27.  
  28. private void init(){
  29. StringItem si = new StringItem(null, "Next Screen");
  30. append(si);
  31. }
  32.  
  33. public void commandAction(Command c, Displayable d){}
  34. }
Quick reply to this message  
Java Syntax
  1. package myProject.screens;
  2.  
  3. /**
  4.  * Created by IntelliJ IDEA.
  5.  * User: Peter
  6.  * URL: http://www.peterscorner.co.uk
  7.  * Date: 02-Oct-2009
  8.  * Time: 17:46:18
  9.  */
  10. import java.io.IOException;
  11.  
  12. import javax.microedition.lcdui.Canvas;
  13. import javax.microedition.lcdui.Display;
  14. import javax.microedition.lcdui.Graphics;
  15. import javax.microedition.lcdui.Image;
  16.  
  17. import myProject.ProjectMIDlet;
  18.  
  19. /**
  20.  * A simple splash screen.
  21.  */
  22. public class SplashScreen extends Canvas implements Runnable {
  23.  
  24. private Image mImage;
  25. private ProjectMIDlet projectMIDlet;
  26.  
  27. /**
  28.   * The constructor attempts to load the named image and begins a timeout
  29.   * thread. The splash screen can be dismissed with a key press,
  30.   * a pointer press, or a timeout
  31.   * @param projectMIDlet instance of MIDlet
  32.   */
  33. public SplashScreen(ProjectMIDlet projectMIDlet){
  34. this.projectMIDlet = projectMIDlet;
  35. try{
  36. mImage = Image.createImage("/res/badge.jpg");
  37. Thread t = new Thread(this);
  38. t.start();
  39. }
  40. catch(IOException e){
  41. e.printStackTrace();
  42. }
  43. }
  44.  
  45. /**
  46.   * Paints the image centered on the screen.
  47.   */
  48. public void paint(Graphics g) {
  49. int width = getWidth();
  50. int height = getHeight();
  51.  
  52. //set background color to overdraw what ever was previously displayed
  53. g.setColor(0x000000);
  54. g.fillRect(0,0, width, height);
  55. g.drawImage(mImage, width / 2, height / 2,
  56. Graphics.HCENTER | Graphics.VCENTER);
  57. }
  58.  
  59. /**
  60.   * Dismisses the splash screen with a key press or a pointer press
  61.   */
  62. public void dismiss() {
  63. if (isShown())
  64. Display.getDisplay(projectMIDlet).setCurrent(new NextScreen(projectMIDlet));
  65. }
  66.  
  67. /**
  68.   * Default timeout with thread
  69.   */
  70. public void run() {
  71. try {
  72. Thread.sleep(3000);//set for 3 seconds
  73. }
  74. catch (InterruptedException e) {
  75. System.out.println("InterruptedException");
  76. e.printStackTrace();
  77. }
  78. dismiss();
  79. }
  80.  
  81. /**
  82.   * A key release event triggers the dismiss()
  83.   * method to be called.
  84.   */
  85. public void keyReleased(int keyCode) {
  86. dismiss();
  87. }
  88.  
  89. /**
  90.   * A pointer release event triggers the dismiss()
  91.   * method to be called.
  92.   */
  93. public void pointerReleased(int x, int y) {
  94. dismiss();
  95. }
  96. }

Tags
j2me, jme, screen, splash, tutorial-sample

Message:


Similar Threads
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC