You are here

J2ME Polish

Mobile Developer's Guide to the Galaxy- from J2mePolish site

Blog Terms: 

News from J2mepolish site:

Mobile Developer's Guide- first edition out now

Get CellId and other Imformation from mobile phones via J2ME

Blog Terms: 

Without GPS or Network Operator we can still use the Location Based Service, via the help of CellId(Cell ID the location of Cell Identities of GSM-networks). Google has one enormous database of cell ids which are linked to a longitude and latitude position, that why Google Map client know where you are even you have no embedded GPS--it is not open.

"Cannot allocate memory" OutofMemory when call Ant to build Polish project in Tomcat

Blog Terms: 

I have written one J2EE web service which was run in Tomcat, this service will call Ant to build one J2ME Polish project. It can be run without problem, aber will got such exception "ProGuard is unable to obfuscate: Cannot run
program "java": error=12, Cannot allocate memory" after several times' building. This is abvious OutofMemory exception.

Tomcat service was run on CentOS linux, the first thing what i thought is to increase the initial memory of Tomcat.

J2ME Application Icon sizes for Devices (T)

Blog Terms: 

Wondering about correct size of application icons for mobile devices?

Here is the list :-)

Application Icon sizes
From J2me wiki

Many phones use many different size icons to display next to the
applications name. Please add to and edit this list when you can
confirm exactly what the maximum icon size is for a specific phone.

Strange Exceptions when Compiling Code and Solutions in J2ME Polish (updated often)

Blog Terms: 

During the J2ME development with J2ME Polish, sometimes I met some strange exception when I debugged or compiled the codes. In this post I will write down them all and the according solution(if I have Tongue out), so this post will be updated frequently.

Touch J2ME Polish--6. GUI DIY with CSS style definition

Blog Terms: 

I MUST say firstly that using CSS to define the GUI in J2ME application is a VERY VERY SMART idea!
What is CSS?
Cascading Style Sheets, was widely used in XHTML and webdesigning, the designers cant separate the style from the HTML userinterface, that means the programmer can only do his part of HTML interface designing, and the beautification and decoration of interface could be left to art designer. For example, look at the menu of this page, if one day I am tired of the current style of, I DO NOT have to modify the HTML code for each page, I just need modify the css file and every page will change its style. 

Touch J2ME Polish--5. First Application, begin with Loading Splash Screen

Blog Terms: 

If you have used some J2ME applicaitons, e.g. some games, almost all of them will give you one loading splash screen when you start the game, or before you enter the next stage the waiting splash screen will tell you the progress of data loading. The standard solution is to provide a splash screen and do the necessary initialization in a background thread. And if you have done this before, your code will look like this:

//firstly difine one class to draw the logo and string on canvas
    public class SplashCanvas extends Canvas {
        protected void paint(Graphics g){
            try {
            } catch ( e) {
                System.out.println("Load image error when initializing Exception happens:" + e.getMessage());
            g.drawImage(icon_start,getWidth()/2, getHeight()/2-15, Graphics.BOTTOM| Graphics.HCENTER);
            g.drawString("EasyWMS 1.00", getWidth()/2, getHeight()/2, Graphics.BOTTOM| Graphics.HCENTER );
            g.drawString("Loading...", getWidth()/2, getHeight()/2+15, Graphics.BOTTOM| Graphics.HCENTER );
        protected Graphics clearScreen(Graphics g) {
              // clear screen
              g.setColor(255, 255, 255);
              g.drawRect(0, 0, this.getWidth(), this.getHeight());
              return g;

//will run the splash screen in one background thread, for the further calling
   public class SplashScreen implements Runnable{
        private SplashCanvas splashCanvas;
        public void run(){
            splashCanvas = new SplashCanvas ();     
                }catch(Exception e){}

//impletement this class as one thread, like this:
//public class genisMIDlet extends MIDlet implements Runnable{
//then give the run method
    public void run(){
            // soft loop          
//the splash will keep on displaying 3 seconds and then go to the main form automatically
    private void doTimeConsumingInit(){
        // Just mimic some lengthy initialization for 3 secs
        long endTime= System.currentTimeMillis()+3000;
        while(System.currentTimeMillis()<endTime ){}

        controller=new UIController(this);

//at last,  open 2 threads when initialize the application
    protected void startApp() throws MIDletStateChangeException {
        Thread splashthread= new Thread(new genisMIDlet.SplashScreen());

     //now you can also load the data from database or something.....
        Thread thisThread = new Thread(this);

And if there are others progress need to give the user one waiting screen, those code will be write again with differnt string and image. Are you tired? Yes, I am tired of this.Polish provides the de.enough.polish.ui.splash.InitializerSplashScreen for this task. The splash screen shows an image along with an optional string message and initialize the actual application in a backgroud thread.  This is the code example:

package de.enough.polish.sample.splashScreen;


import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;
import de.enough.polish.ui.splash.InitializerSplashScreen;
import de.enough.polish.ui.splash.ApplicationInitializer;;

public class SplashScreenDemo extends MIDlet
//#if !polish.clases.ApplicationInitializer:defined
    implements ApplicationInitializer
    private Screen mainScreen;
    private Display display;
    protected void startApp() throws MIDletStateChangeException {
        this.display = Display.getDisplay(this);
        if(this.mainScreen !=null){
            //the MIDlet has been paused;
              //the MIDlet is started for this first time
                  Image image = Image.createImage("/welcome.png");
                  int backgroundColor = 0xFFFFFF;
                  String readyMessage = "Press any key to continue...";
                  //Set readyMessage = null to forward to the next
                  //displayabe as soon as it's available
                  int messageColor = 0xFF0000;
                  InitializerSplashScreen splashScreen = new InitializerSplashScreen(this.display
                  ,image, backgroundColor, readyMessage,messageColor,this);
              }catch(IOException e){
                throw new MIDletStateChangeException("Unable to load splash image");

    public Displayable initApp(){
        //initialize the application.e.g. read data from record store,etc
        //now create the main menu screen:
        //e.g. this.mainScreen = new Form("Main Form");

        this.mainScreen = new Form("Main Form");

        return this.mainScreen;

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
        // TODO Auto-generated method stub

    protected void pauseApp() {
        // TODO Auto-generated method stub
Splash Loading Screen:

Go to the main Form:

Have you seen that, only one function could do everything, creates a new InitializerSplashScreen using the internal default view.
public InitializerSplashScreen(Display display, Image image, int backgroundColor, java.lang.String readyMessage, int messageColor, ApplicationInitializer initializer)The message will be shown in the default font.Parameters:

Touch J2ME Polish--4. Test with Polish Example

Blog Terms: 

If you selected install the polish example when you install the polish, now you can find about 10 examples in samples folder in your polish root folder. You havnt found? I have told you before, please update your harddisk to a big one~
Those examples are very very valuable for the polish beginners, including me. They are the basic interface of Polish UI and some simple application to help you create your own project.

Touch J2ME Polish--3. Debug and Build with Ant

Blog Terms: 

At first you should pay attenion to the source folder, if you have converted one existing project to Polish project. Polish's default source directoty is source/src, and default resource directory is resources. Please go to the project's properties and change the Java Build Path setting like this. Otherwise you can not build it successfully.

Now you can debug or build the project with Ant.

Touch J2ME Polish--2. Create Projects or Convert Existing Projects

Blog Terms: 
After the installation of Polish, we can create Polish Project NOW~~

Create New J2ME Projects

1. Open File->New->Project, find the J2ME Plish Project in Java directory. (Why not in J2ME directory?) A funny chelonian, lol

2. Enter a project name, and click Generate Template if you like, it will create a MIDlet template in a package you named.


Subscribe to RSS - J2ME Polish