Simple example of WaitScreen component

There is WaitScreen component () in the Palette of the Mobility Pack when you are working in a Visual Midlet. This component is available only for MIDP2.0 and Visual Midlet in MIDP 2.0. It is designed for run of longer tasks that can block UI in background. The task will run and you will see the WaitScreen with a text or image. When the task finishs then it continues on next screen. There is SimpleCancellableTask non-visual component for definition of the task for the WaitScreen. You can find the SimpleCancellableTask in Resources in Palette. Drag and drop it into your Visual Design MIDlet.
Open Properties of the new SimpleCancellableTask and you can define Executable Method Body. The Executable Method Body is the code that will run on the background when the WaitScreen appears on the screen of the device. Note that the WaitScreen can end either with Failure or with Success. When the SimpleCancellableTask ends without an exception then it will continue to the Success screen otherwise it will go to the Failure screen.

I created a simple example that connect to internet and shows a price of a stock. I reused some codes from

The main problem that found when I was creating the example was that the simpleShockPriceTextBox component is created and used in setNextDisplayable method of the WaitScreen before the data are downloaded from network. I had to add call of setString(...) of the showShockPriceTextBox at the end of the Executable Method Body of the SimpleCancellableTask. It updated the value correctly.
I tried a different approach before. I set showShockPriceTextBox=null and hoped that it will re-create the component again with the right values but it didn't worked in that way :(


Thanks for providing some valuable information about this component. This is the second time I couldn't find anything except your site about things I really needed to know. Regards, Daniel

Posted by Daniel on November 28, 2006 at 08:20 AM CET #

You're welcome, Daniel.
I'm open to write about any other issues? Any idea what would interest you ? (of course, something what is not described somewhere else).

Posted by Lukas on November 28, 2006 at 01:46 PM CET #

hello, nice tips!! can you write others tips same as this? thank you!

Posted by Pablo A Castillo on December 29, 2006 at 08:04 AM CET #

Thanks Pablo!
I can write more tips - the question is "about what", what are you interested in? Ideas are welcome..

Posted by Lukas on December 29, 2006 at 09:21 AM CET #

Well, as it turns out, in NetBeans' implementation of CancellableTask (SimpleCancellableTask) they have not bothered implementing the cancel() method - wasn't this the whole point of the Cancellable, one wonders? At least according to the javadoc API (and also trying it out the code).
It would not be a big deal, as one could easily implemente MyCancellableTask with cancel() trivially implemented by setting a flag (stopped) to true.
However, given the way the autogenerated code works in NB Mobile pack, this is not easily achieved and leaves quite a lot of hand-coding to do.
I also noticed that in your sample code you are using now deprecated methods, so maybe worth updating it ;-)
Am I missing something here?
Comments warmly welcome!

Posted by Marco Massenzio on March 19, 2007 at 12:33 PM CET #

@Marco : there is only one way how to quit the SimpleCancellableTask. Throw an exception. This is really simple implementation of the Cancellable interface. Anyway it worked for most cases that we used. The usual use of the task is to connect to internet. When it fails an exception is thrown and task "cancel".
You can implement it in you way.

About the updating of the source code. You are right. They changed the approach. (see
I'll update thi post a little bit.

Posted by Lukas on March 20, 2007 at 03:41 AM CET #

thanks man!

Posted by Eko on January 15, 2008 at 06:11 PM CET #


In a waitscreen how can i control which point (success or failure) the program may take depending the return value of the called task...

Posted by max simon on July 13, 2008 at 11:57 AM CEST #

The SUCCESS is when your code doesn't end with exception. If an exception is thrown then it continue the FAILURE path. Therefore you have to either change your method to throw exception when it should fail or you have to check the value in the waitscreen execute body and then throw the exception to let the waitscreen know that the method failed

Posted by Lukas on July 17, 2008 at 04:51 AM CEST #

thanks lukas
I'm going to do some test

Posted by Max Simon on July 17, 2008 at 08:32 AM CEST #

Hi Lukas,
I was recently looking at the tutorial project on .

I wanted to add a WaitScreen to the project for
loading a file so that when a \*.txt file is selected
{ie. inputFile.getName().endsWith("txt")}
the txt file contents are displayed in a textbox as per the the supplied readfile() method. However, if a non-txt file is selected an Alert should pop-up indicating that the wrong file type was selected, and the filebrowser should be displayed once again.
I got as far as adding a Waitscreen and a "Wrong file type" Alert. Could you suggest how I can invoke the FAILURE_COMMAND in the WaitScreen so that the "Wrong file type" Alert can get display. Any additional suggestion to accomplish this file type checking would be welcomed.

Thanks, Daniel

Posted by Daniel H on July 24, 2008 at 11:14 AM CEST #

@Daniel H: what about:
public void execute() throws Exception {
// write task-execution user code here
if(getFileBrowser().getSelectedFile().getName().endsWith(".txt")) {
//process the file
} else {
throw new Exception("File isn't text file");


However you might think about better solution. IMO, you should move the if(.txt) condition into IF component of Flow designer. I'll try to attach a sample project later.

Posted by Lukas on July 28, 2008 at 02:18 AM CEST #


i dont know if my question belong to this post but as i've assumed you(Lukas) said any questions and my questions fall under the any part.let me get to it right.

im knew to MIDlets and i want to implement a choicegroup with choiceitems from the database but the tricky part is i have a series of choicegroups.example to ellaborate what my idea after you pick the first option on the first choicegroup, choicegroup two should retrieve data from (Network)database depending on the choice selected from the first choicegroup.

i dont know if its clear but i hope you get what i'm saying.

nice post very informative.

Posted by ruzive on February 01, 2010 at 12:41 PM CET #

@ruzive: I'm sorry I didn't get it. You'll have to describe it in more details ;)

Posted by Lukas on February 02, 2010 at 02:42 AM CET #

@Lukas let me describe it in another way.i want to develop an mobile application which loads data into the combobox depending on the option that is picked on the first combobox i want to have four comboboxes on a single screen.The data is coming from the database.

Another question is it possible to use a database with JavaME,it so please can you show me how and if not, how much data can the RMS(RecordStore)say all the Nokia models

Posted by ruzive on February 02, 2010 at 07:09 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed

This is the main channel to share news, tips and other stuff related to my work. Sometimes you can find even personal stuff. Enjoy your reading...


« June 2016

No bookmarks in folder