954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Java GUI thread

Okey , This is suppose to be a chat and server program and I am down to the last part but I cant seem to figure this out.
I Use the JtextField to get the Input from the user and it is suppose to hold it until the sent button is pressed. But when I pressed it the button gets stucked for a few second and it sends a bunch of message out and I cant figure out what is wrong with the code

private void sendButton()
   {
	 //  this is called by the send button 
      class Sentmessage implements ActionListener
      {
         public void actionPerformed(ActionEvent event)
         {
        	
        	 try
             {  
        		 streamOut.writeUTF(ChatInput.getText());
        		 streamOut.flush();
             
             }
             catch(IOException ioe)
             { 
            	 System.out.println("Sending error: " + ioe.getMessage());
                stop();
             }
         }
      }
      Sentmessage listener = new Sentmessage();
      send.addActionListener(listener);
   }

that is what is called

public void run()
   {  while (thread != null)
      {  
	   
	   sendButton();
      }
   }


Is this something to do with the thread?

ricedragon
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 
while (thread != null) {

What is that ? It looks like infinite loop to me. why did you put the while loop there? Is that the entire code you have posted? what are the errors you are getting? Have you tried debugging your code from the error messages?

harinath_2007
Posting Whiz
355 posts since Aug 2010
Reputation Points: 78
Solved Threads: 36
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: