I am working on a client-server app in java.. Simple interface contain textField to write message and textarea to show messages exchanged. however, the problem is how to get the input from the textfield and send it? I mean it must wait until I enter message and press Enter key and then continue. thanks in advance!
Asked
Active
Viewed 60 times
0
-
Here's the official swing tutorial Read it. https://docs.oracle.com/javase/tutorial/uiswing/index.html – JB Nizet Mar 24 '19 at 20:00
-
thanks a lot for that, but what I am looking for is how to build input stream that takes input from textfield, and the important point is how to make the app waiting for input while exchanging messages, I wish it is clear now!! – nader al-sleman Mar 25 '19 at 05:44
-
It has always bee clear. That's not, at all, how a GUI written using Swing works. You don't wait for things to be entered. Instead, the text field fires events to notify you when something is entered. It's all explained in the tutorial of course. And you need to read documentation if you want to understand how things work and how to use Swing. So just do it. Read the tutorial. Is reading really so hard? – JB Nizet Mar 25 '19 at 07:32
-
Add an `ActionListener` to the text field. When the user presses the `enter` key, it will fire an event that is used by the `actionPerformed` method of the listener. For any more help, post a [mre]. – Andrew Thompson Oct 30 '21 at 18:21