Sunday 15 April 2012

user interface - JavaFX GUI stuck -


I'm new here and I'm new to Java programming but I only have to sign up to ask you for this reason Still, I am writing TCP Clients. I made two threads: to read from a system. And to send the socket, and the other to read from the socket and the system To write in out It worked fine but now I need to create a GUI and I know that if I want to keep my GUI interactive, then I need to use the task and / or service, but I do not know that my thread How to be created as a service Here's the code (which works in the terminal):

  Expands the public stable class ReadThread thread {BufferedReader in; String word; ReadThread (BufferedReader in) {this.in = in; } @ Override Public Wide Run ({{(word = in.readline ()) = = null System.out.println (word); } Hold (IOException pre) {Logger.getLogger (Client.class.getName ()). Log (Level.SEVERE, null, ex); }}}   

Similarly, I have created WriteThread, but I do not want to make this post dirty ... Anyway, when I try to apply it as a service So to "generate" me in the last one which has some other errors and so on and so on. I would be happy if you helped me on my special case, I would probably read all Java FX GUI problems on this site. Thanks, thanks in advance and sorry for the long post! :

In this way I apply the service

  Public Class ReadService service extension [BufferedReader in; String word; @ Override Protected Tasks (Tiles) {Return New Work} {@Override Safe Object Call ()) throws exceptions {try {while ((word = in.readline ()) = null system.out.println (word) ; } Hold (IOException pre) {Logger.getLogger (Client.class.getName ()). Log (Level.SEVERE, null, ex); } Return tap; }}; } Public BufferedReader getIn () {Return; } Public Zero Setin (BufferedReader in) {this.in = in; }}   

And where you have to call your service.

  Read Service Seva = New ReidSwire (); ReadService.setIn (// inside); ReadService.restart ();   

You can also add some handlers when your service starts, cancel, fails, ends ...

  readService.setOnSceeded (new EventHandler & lt; WorkerStateEvent & gt; () {@ Override Public Wide Handle (Workstate Event Workstate Event) {// Proceed here}}};   

that he

No comments:

Post a Comment