public void aMethod(){
new Thread(new Runnable() {
public void run() {
int decide = JOptionPane.showConfirmDialog(null, confirmName?, JOptionPane.YES_NO_OPTION);
}
}).start();
System.out.println("Number of decison " + decide); //Can't find symbol "decide"
}
JOptionPane can’t run without being put to a thread(I don’t know why). Yet when put it to a thread, I can’t get the varible decide from that.
P/s: This is a method in callbackImplement Java RMI.
Thank you. happy new year 😛
You can define custom fields in your
Runnablesubclass and pass them through the constructor:As for why you need to invoke Swing methods on their own thread, you can read this article: Threads and Swing. In fact, you shouldn’t be creating your own thread but instead just schedule it on the Swing event dispatch thread: