Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch javaFX app from java code

I have a JavaFX card game currently running for single player. I want to enable multiple players playing over TCP socket connections, for which I have a simple client/server skeleton program written in java.

My problem is: the server/client code is in java. How do I launch the javafx app from the client java code, and then update it based on the gamestate returned from the server?

Simple server-client loop will be: client sends action, server updates gamestate, and echoes it back out to client.

client pseudo-code

if(!clientGUI.isInitialised())
   initJavaFXapp();  // I am struggling to do this

//keep reading from server 
if(obj instanceOf gameState)
    javaFXGUI.update(obj)

I am beginner to using javaFX, and I utilised the graphics aspect as my app is based on it.

Any help would be much appreciated.

like image 618
Atif Hussain Avatar asked Feb 20 '13 02:02

Atif Hussain


1 Answers

Assuming MyApplication class extends javafx.application.Application you can launch it next way:

 javafx.application.Application.launch(MyApplication.class);
like image 120
Sergey Grinev Avatar answered Oct 23 '22 11:10

Sergey Grinev