JavaMEComponent MELibrary



This document is a part of Java ME Custom Component Creation tutorial.

It will help you to implement new Java ME component based on existing SplashScreen component implementation (NetBeans extension of existing Java ME components).

We will add status string to the display. Component class will be extended with three methods to manage displayed status message:

  • void setStatus(int) - set finished percents
  • int getStatus() - get finished percents
  • void setStatusPrefix(String) - prefix to add to status message

In our implementation we will extend showNotify() method to start process that will update status value periodically.


If you not familiar with NetBeans Java ME plugin look at this Document before you start: NetBeans 6.0 CLDC/MIDP Development Quick Start Guide

  1. Create new Java ME Mobile Application project
    1. Name it SplashScreenExtLibrary
    2. Don't create Hello midlet
  2. Add new package org.netbeans.microedition.lcdui.custom to created project
  3. Add new Java Class to just added package
    1. Name it SplashScreenStatus
  4. Replace SplashScreenStatus class implementation with the following code. Then we will describe new implementation.
public class SplashScreenStatus extends SplashScreen{ private int status = 0; public SplashScreenStatus(Display display) throws IllegalArgumentException { super(display); } public void setStatus(int status) { this.status = status; repaint(); } public int getStatus() { return this.status; } /** * Gets the status text to be painted on the screen. * @return text */ public String getStatusString(){ return "status: " + getStatus() + "%"; } protected void showNotify() { super.showNotify(); if (getTimeout() > 0) { Watchdog w = new Watchdog(getTimeout()); w.start(); } } protected void paint(Graphics g) { super.paint(g); final int centerX = g.getClipWidth() / 2 + g.getClipX(); final int centerY = g.getClipHeight() + g.getClipY(); g.drawString(getStatusString(), centerX, centerY, Graphics.HCENTER | Graphics.BOTTOM); } private class Watchdog extends Thread { private int timeout; private Watchdog(int timeout) { this.timeout = timeout; } public void run() { int time = 0; int step = (int)timeout / 10; while (time < timeout){ try { Thread.sleep(step); time += step; setStatus(time*100/timeout); } catch (InterruptedException ie) { time = timeout; } } } } }
    1. To create SplashScreenStatus based on existing org.netbeans.microedition.lcdui.SplashScreen implementation, we have made the following changes
      1. extends clause is added
        public class SplashScreenStatus extends SplashScreen
      2. constructor with Display parameter is added
public SplashScreenStatus(Display display) throws IllegalArgumentException { super(display); }
    1. We have extended SplashScreen by adding status string at the Bottom of display
      1. void setStatus(String) to set status string
      2. String getStatus() to get status string
      3. have overrided paint(Graphics) method to draw status string on display
      4. have overrided showNotify() method to update status text
  1. Add to project Libraries and Resources list NetBeans MIDP Components library, which contains org.netbeans.microedition.lcdui.SplashScreen
    1. Open SplashScreenExtLibrary project Propeties
    2. Go to Build | Libraries & Resources category
    3. Press Add Library... button
    4. in Opened Add Libraries dialog select NetBeans MIDP Components library and press Add Library button
    5. Press OK button in project propeeties dialog
  2. Fix imports in SplashScreenStatus source by using Ctrl+Shift+I shortcut or Fix Imports command from editor context menu
  3. build SplashScreenExtLibrary project


As a result of this tutorial you get Project with new Java ME component SplashScreenStatus implementation. Project is compiled into jar file SplashScreenExtLibrary/dist/SplashScreenExtLibrary.jar

You may download zipped project created in this tutorial:

NOTE: To run project from zip file you have to change NetBeans Platform to one registered in your Netbeans IDE.

Now you can continue with the next tutorial step: Part Two: Java ME Visual Designer component

Back to Java ME Custom Component Creation tutorial

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo