Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFX access gui button action from another thread
    text
    copied!<p>I am starting a JavaFX gui application from another class, namely <code>StartClient</code> by doing. </p> <pre class="lang-java prettyprint-override"><code>public class StartClient extends Application { private Table gui; @Override public void start(Stage stage) throws Exception { gui = new Table(); gui.start(stage); </code></pre> <p> I start a <code>Task</code> through which I connect to a server and receive the turns assigned by the server, which I set in the gui using <code>Platform.runLater</code>.</p> <pre class="lang-java prettyprint-override"><code>Task&lt;Void&gt; task = new Task&lt;Void&gt;() { @Override protected Void call() throws Exception { connectToServer(); // connect to server, set up socket, i/o streams Object read = inputStream.readObject(); if (read instanceof String) { turn = //parseInt from read Platform.runLater(new Runnable() { public void run() { gui.setPlayerID(turn); } }); } } }; //end of task </code></pre> <p> What my problem is that I want to get the move made by a player if it is their turn and send it back to the server doing something like this: </p> <pre><code>if(networkClientID == gui.getState().getTurn()){ do { action = Table.getAction(); //static getAction returns the move from the table if there was one } while (action == -1); outputStream.writeObject(action + ""); // write out turn } </code></pre> <p>Do I do this on background <code>Thread</code> (I am reading a static variable from the gui or should I do this in javaFX thread i.e. inside <code>Platform.runLater</code>, I have tried it, but not getting anywhere, my program is getting stuck.)</p> <p>Any suggestions, help, advise welcome on how to solve this problem. Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload