Answer the question
In order to leave comments, you need to log in
Java: GUI Interaction with Network Module
Good afternoon,
To study Java, I decided to write a network game with a client and server part. The client roughly speaking consists of two classes: Connection, UserInterface. While the UserInterface was purely console everything was great.
command = userInterface.getCommand(); // blocking call
sendToServer(command);
where inside getCommand is System.in.read();
Now I'm changing from a console interface to a Swing-based GUI and want to call
command = userInterface.getCommand(); like so.
but the situation is different now. getCommand() should only return when the user fires an event with the mouse or keyboard.
In this regard, it is not very clear to me how the getCommand function can be implemented.
Any suggestions are welcome, a link to something to read.
Thanks
Answer the question
In order to leave comments, you need to log in
Everything is fine, only getCommand must be called on the SwingWorker. Read here . The point is to perform all at least some long operations in a separate thread without blocking the UI.
add a MouseListener and a KeyListener to your swing object. and as a result of the desired keyboard shortcuts or on mouseReleased call sendToServer(command)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question