I can't set a JTextField's value
Author |
Message |
andrew.
|
Posted: Fri Jan 08, 2010 8:23 pm Post subject: I can't set a JTextField's value |
|
|
Hi guys,
So for my school project, we have to make a chat program. Basically, there's a server and the clients can talk to each other through the server. Right now, the server is set up and everything is functional, so I am creating a GUI for the client. I am having trouble with the send button. The button works, but the problem is the when I use typingBox.setText ("") to reset the text field to be empty, it still keeps the text that was there before. I know the button and the ActionListener works because my other class sends a message to the server, and also sends the same message back to my "GUI" class to be displayed on screen. Also, I would like to make the enter button press send. I know there's a way to do it, but I can't remember how.
I attached my code. You can run it, but obviously you won't get replies from the server because it's not on. The main method is in Client.java, so compile both files and run that.
I should also mention that the problem is on line 82 of GUI.java and the GUI was created with Jigloo, so it seems a bit messy. Anyways, it's not too hard to figure out.
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
GUI.java |
Filesize: |
3.6 KB |
Downloaded: |
104 Time(s) |
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Client.java |
Filesize: |
1.67 KB |
Downloaded: |
99 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Barbarrosa
![](http://compsci.ca/v3/uploads/user_avatars/12538789384c18775f61c5e.jpg)
|
Posted: Sat Jan 09, 2010 1:58 am Post subject: Re: I can't set a JTextField's value |
|
|
That's strange. I ran your code, and only got that result when it threw a NullPointerException trying to output to the server. Commenting those lines makes it work just fine, without the problem you mentioned.
Is everything getting to the server alright, and is the server processing it how it should?
|
|
|
|
|
![](images/spacer.gif) |
andrew.
|
Posted: Sat Jan 09, 2010 12:58 pm Post subject: RE:I can\'t set a JTextField\'s value |
|
|
That's so weird! I can't say right now, with my GUI if it's getting to the server because the server is at school and I don't have the source for it. But yesterday, it connected and send the message that was commented out, and it got a reply from the server. I will have to try it at school to be sure, but it's weird that it does this.
Anyways, let's ignore that problem for now, I will figure it out later. How can I make the "typingBox" field the default field when the window opens up (so that the typing cursor is already there)?
|
|
|
|
|
![](images/spacer.gif) |
|
|