1
votes

In the old GUI builder, I would just press "next form" in the command. In the new GUI builder, I am trying to make it through code. However, it does not wait for 5 seconds, the app goes straight into the next form.

What I want to do: stay in Splash for 5 seconds, then go to the login form. How would that work?

My forms: Splash.java, that has the GIF animation. Login.java (next form) Myapplication.java (main form)

Main file, myapplication code:

public void start() {
    if(current != null){
        current.show();
        return;
    }
    new Splash().show();
    try {
        Thread.sleep(5000);
    } catch (InterruptedException ex) {
    }
    new Login().show();
}

UPDATE: I added the sleep code to the LOGIN form, and every time i go there, it waits 5 seconds. Is this the optimal way to do this? public Login() {

this(com.codename1.ui.util.Resources.getGlobalResources());

   try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
}

UPDATE 2:

 public void start() {
        if(current != null){
            current.show();

            return;
        }
        new Splash().show();
     //   new login().show();





            new UITimer(() -> {
        new login().show();
}).schedule(3000, false, new login());

not working.

1
As @SolStack mentioned you should use UITimer sleep holds the EDT in place and doesn't let it draw or do anything (e.g. showing a Form) see codenameone.com/manual/edt.html - Shai Almog
thanks. did one more update, still missing something. - C Java

1 Answers

2
votes

Try using the Codename One UITimer class instead.

https://www.codenameone.com/javadoc/com/codename1/ui/util/UITimer.html

Something along the lines of:

new UITimer(() -> {
  new Login().show();
}).schedule(5000, false, this);