Where to add actionPerformed
2 posts in topic
Flat View  Flat View

Posted By:   Amber_Pink
Posted On:   Thursday, April 6, 2006 02:58 AM

Hi. I am new to java socket programming. I would like to ask a question. I have a button in the server program but i'm not sure as to where to put the actionPerformed() method in which the logic of sending response to multiple clients is contained. I have to copy the client, in and output streams declarations in run() in this actionPerformed() method which i think is not appropriate. Anyone can give any suggestions? Thanks.

Re: Where to add actionPerformed

Posted By:   Anonymous  
Posted On:   Monday, April 17, 2006 06:58 AM

This is a good tutorial to begin the Socket Programming. I hope this helps.


Re: Where to add actionPerformed

Posted By:   Robert_Lybarger  
Posted On:   Thursday, April 6, 2006 08:16 PM

wow... that's a rather confusing question. you might need to clarify some basic things about what your little app is doing in a "big picture" sort of way... example "I have a server program that allows multiple clients to connect to it. The client allows a user to type a message in a text field, press a button, and sends the message to the server. The server's job is to send this message to the other clients," ... and then it'd be clearer to understand what your problem might be with actionPerformed.

First... how does the server have a button in it (as you stated)? That notwithstanding, "actionPerformed" should be implemented in the "ActionListener" object that has the job of "passing along" the fact that the event took place. The presence of distributing an application over sockets doesn't really change the usage pattern of the Button->event->actionPerformed concept. That's not a great answer, but it wasn't a great question. ;) In the case of my example above, actionPerformed is implemented in the client-side GUI; the code for that method might just hand off the message to some other [private] method that pumps it across the socket connection to the server. What happens at that point would depend on the/your design of the/your client/server interaction protocol.

About | Sitemap | Contact