jeudi 21 juillet 2016

JAVA press button and wait some seconds

i've a problem: i have a simple GUI app with a single button, when i press the button theorically it should print a message and after 2 seconds it should print another message, but when i use Thread.sleep(x); it dont execute the code above it and wait, this is the code:

private void button1(java.awt.event.ActionEvent evt){

 System.out.println("lol 1");

 try {
        Thread.sleep(2000);
    } catch (InterruptedException ex) {
        System.out.println("error");
}

System.out.println("lol 2");
}

But obiuvsly this dont work like i want.. cause it wait 2 seconds and the print lol 1 and lol 2 in the same istant!

Aucun commentaire:

Enregistrer un commentaire