0

I need to perform a method after the clicking of a JButton in a Java Project. I'm making a client-server game and after the click of a button I need that the client/server start to wait untill the opponent perform a click. The problem is that at the end of the action listener code I start a loop end untill the opponent don't perform another click the jbutton stays clicked..

public void actionPerformed(ActionEvent e) {
     JButton o = (JButton)e.getSource();
     String name = o.getName().substring(3);
     Click(Integer.parseInt(name));
     if(isServer)
         ListenServer();
     else
         ListeClient();
}

ListenServer() and ListenClient() are two loop function... How can I call this methods AFTER the click??? Thanks and sorry for the bad english

René Link
  • 48,224
  • 13
  • 108
  • 140

1 Answers1

0

You can use threads and synchronization. See https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CountDownLatch.html for examples.

Paco Abato
  • 3,920
  • 4
  • 31
  • 54