Discussion Board

Results 1 to 2 of 2

Thread: GUI delay bug

  1. #1
    Registered User
    Join Date
    Jun 2010

    GUI delay bug


    i have start to try out lwuit.

    I have build 3 screens. When ein push a button cmdSlide, i want show the 2. screen for a certain time (2 sec) and slide without to push a button to the 3. screen.

    But with this code it is not possible. With Thread.sleep(2000) 2 sec wait on the 1. screen, not on the 2. screen. The 2 sec comes everytime with the button-event.
    Anyone an idea how i could solve this delay problem to get a delay on the 2. screen.


    import java.io.IOException;

    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;

    import com.sun.lwuit.Button;
    import com.sun.lwuit.Command;
    import com.sun.lwuit.Container;
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Label;
    import com.sun.lwuit.animations.CommonTransitions;
    import com.sun.lwuit.animations.Transition3D;
    import com.sun.lwuit.events.ActionEvent;
    import com.sun.lwuit.events.ActionListener;
    import com.sun.lwuit.layouts.BorderLayout;
    import com.sun.lwuit.layouts.BoxLayout;
    import com.sun.lwuit.plaf.UIManager;
    import com.sun.lwuit.util.Resources;

    public class BasicForm extends MIDlet implements ActionListener {

    private Form form1;
    private Form form2;
    private Form form3;

    //private Command cmdRotate = new Command("Rotate");
    private Command cmdSlide = new Command("Slide");
    private Command cmdSlide2 = new Command("Slide2");
    private Command cmdSlide3 = new Command("Slide3");

    private Command cmdExit = new Command("Exit");

    public BasicForm() {
    //Initialize the LWUIT

    protected void startApp() throws MIDletStateChangeException {
    //Load the Theme
    Resources r;
    try {
    r = Resources.open("/LWUITtheme.res");
    } catch (IOException e) {

    form1 = new Form("Form 1");
    form1.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    form1.addComponent(0,null,new Label("This is the first Form"));
    form1.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));

    //Setup Form 2
    form2 = new Form("Form 2");
    form2.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    form2.addComponent(0,null,new Label("This is the second Form"));
    form2.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));

    form3 = new Form("Form 3");
    form3.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
    form3.addComponent(0,null,new Label("This is the third Form"));
    form3.setTransitionInAnimator(CommonTransitions.createSlide(CommonTransitions.SLIDE_HORIZONTAL, false, 1000));


    public void actionPerformed(ActionEvent evt) {
    //check which command cliked
    if (evt.getCommand()==cmdExit) {
    } else if (evt.getCommand()==cmdSlide) {
    try {
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block


    }else if (evt.getCommand()==cmdSlide3) {

    protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {

    protected void pauseApp() {


  2. #2
    Regular Contributor
    Join Date
    Nov 2008

    Re: GUI delay bug


    The problem you are facing is one all beginners face before too long, and even experienced Java developers re-encounter from time to time. When your user interacts with the GUI (e.g. clicks a button), your actionPerformed method gets invoked, but it is being invoked on the the System event thread. You must not tie up this thread, because if you do the system will be unresponsive. By "unresponsive" I mean it will not respond to additional user actions, and it will not update the display.

    In your program the actionPerformed method is trying to update the display and then sleep for SECONDS (an eternity), ALL on the system event thread. The GUI cannot be updated during the time you are "hogging" that thread.

    if you want to do any work beyond the most minor bookkeeping you must do it in a different thread. You can create a new thread to do the work, or you can send a messages to an already-running thread to do the work, but if you don't do it in a different thread then... well, you've seen what happens.

    If you don't know about threading then you need to find something to read. It's not a short or simple subject, and certainly can't be explained in a discussion group.

    Good luck.

    Matt Brenner
    UnME2, Inc.

Similar Threads

  1. Replies: 8
    Last Post: 2009-03-31, 09:18
  2. S60V3 - showing GUI from a non GUI exe
    By tal.shahar@mobile-mx.com in forum Symbian
    Replies: 4
    Last Post: 2008-01-02, 08:52
  3. Replies: 1
    Last Post: 2007-04-16, 08:57
  4. Firmware bug or code bug displaying list on 3650
    By blackjack75 in forum Mobile Java General
    Replies: 2
    Last Post: 2003-09-24, 19:52

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts