Sunday, January 23, 2011

Client Implementation: Simple, yet improved JAVA Server Client Application

Now for the client.....

Since we use gui, we have to implement the client side a little careful than the server. We can't just copy and paste the code like we did for the server.

For the client,
1. There should be a method which collect data from the inputstream, which will run until the client says "bye".
2. Certain things should happen when client press the ok button.


Let's take a look at clients GUI.


Rename the topmost JTextField to inputText and the bottom to outputText.
Button will have the name okButton.

As we did in the server we now add a method run().


make sure to run this method in the main class. ;-)

Now we need client to send a message to the server when the user press Go button.
Therefore the following code goes right in the middle of the Go buttons actionPerformd(Event ev) method.
(Note: you have to implement ActionListner for the JFrame class)


So that's it. Oh wait a minute. Almost forgot the sendMessage(String str) method. :-P


So that's it. All finished. 
Now you proceed for the grand testing of the server-client Application. :-)

The complete source code can be found:  here  


No comments:

Post a Comment