开发者

Running a method while Waiting for input

开发者 https://www.devze.com 2023-02-11 19:01 出处:网络
I have an application in which a JOptionPane is called. How can I continuously run a method until the yes on the JO开发者_开发百科ption Pane has been selected?

I have an application in which a JOptionPane is called. How can I continuously run a method until the yes on the JO开发者_开发百科ption Pane has been selected?

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

Thank you!


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


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消