how do I make a method run past X time after pressing a button?

0

I would like to know how I can do so that after X seconds after executing a button, send me to a method that does what I have to do.

A bit of the context: I have a button that gives a jLabel1 with a .gif so I want half of the jbelle1 to run a method that shows me a jLabel2.

   private void golpearActionPerformed(java.awt.event.ActionEvent evt) {                                        
   int x = Integer.parseInt(jTextField1.getText());

    JOptionPane.showMessageDialog(null,"Pasaron x segundos pa que se baje la barra de vida");

    //Esperar el tiempo y mandar al metodo
   ataca(x);

}         

basically I want to find a delay so that the gif is where I want it to be and then if I execute that method ataca(x) to have a "synchronization"

    
asked by Camilo Reyes 02.11.2018 в 06:57
source

1 answer

0

Try to sleep the thread that is happening at that moment for that class   Thread.sleep(10000) , are milliseconds, although I believe that you will not be able to execute other sentences at the same time you do the sleep, for this you should create the thread yourself with either Runneable or extending Thread and manage them with a run.

If you have any other questions, please comment.

    
answered by 02.11.2018 в 08:07