Fernando
Fernando

Reputation: 137

Running a method while Waiting for input

I have an application in which a JOptionPane is called. How can I continuously run a method until the yes on the JOption Pane has been selected?

move = JOptionPane.showInputDialog(null, game + "\n" + "Your Move " + game.inputPrompt() + " ?");

Thank you!

Upvotes: 1

Views: 344

Answers (4)

hhafez
hhafez

Reputation: 39750

You most likely don't want to continuously run a method (that would peg your CPU). Do you mean run it in parallel while waiting for the user input? If then you can start a new thread.

Have a look at the Runnable interface

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runnable.html

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234795

Put your processing in a separate thread. See Concurrency in Swing

Upvotes: 2

ChrisJ
ChrisJ

Reputation: 5251

You should use threads to have several portions of code executing in parallel.

Upvotes: 1

Jesus Ramos
Jesus Ramos

Reputation: 23268

Threading. Create a new thread to do whatever you want until move gets set.

Upvotes: 1

Related Questions