I have a chat window, JTextBox i think, and you hit enter and it invokes an action listener, to send text. It generally works, but now and then i hit enter, and nothing. I have to hit enter again and typically it sends text. the focus is there for typing, but enter is not 100% working.

What could cause this? could i accidently be hitting shift ( every so slightly since its next to enter) as well as enter? can i capture other events like shift enter and control enter?

Mike

You are probably "sending your data" on the event thread which prevents any other event from triggering (and prevent most other GUI functions as well) until it is finished. Your action listener should start another thread and that thread should "send the data", or, better, you should start a new thread at program startup that is responsible for "sending the data" and create a queue that it reads from, and your action listener should then simply place things on that queue.

Edited 6 Years Ago by masijade: n/a

it could be a thread lock issue though i'm not using any locks. i want to try to understand this in terms of my implementation. I have a telnet thread that i've started through an instance of runnable. It does a continual loop ( and sleeps 25 mili every loop) maybe thats the issue its sleeping 25/1000 times. the action listener calls sendMessage() which outputs to the socket. so perhaps input and output are blocking? maybe i need a thread for both input and output? I might be mistaken i thinking since the socket object is on another thread, *both* input and output are threaded. maybe i'm not mistaken.

Mike


Mike

i'm thinking your idea of a que might be what i need. would trying to write to the socket while its being read create an exception causing the event of send to fail? i could manage a que of strings that the input socket can read, and have it send them in order as soon as possible. that way in the telnet loop i know for sure input and output are not happening at the same time. is there a thread safe que implementation in java?

Mike

I'm leaning toward the idea that I had two issues. One had something to do with what you described and one is the shift enter issue. I've been on my interface for several hours a day last few days and i'm pretty sure i had multiple cases where i clearly, at slow speed typed enter, and it didnt send. I think this might be the issue you refrenced.

I set up a ConncurenltyLinedQueue to deal with this. Just took a few minutes actually. the send in the action listener now does queue.add(), and my telnet loop does a poll on every iteration and if the return is not null does a send.

Its a lot better now but i had two instances where it didnt send, after sending a fair number of messages. The first i was typing kind of fast and i'm pretty sure i hit inbetween the shift and enter and almost felt like i missed enter. The second a minute later my left hand this time actually hit enter as i hit shift, as if my mind was telling me to try that and it didnt send so i repeated the eperiment and held down shift and hit enter and nothing. it will never send if you happen do hit shift plus enter.

I am going to mark this as solved and if i dont find data in my web searches on how to handle this, i'll open another thread on the second issue specifically.

thanks
( its definitely better)
Mike

Mike

This question has already been answered. Start a new discussion instead.