|
Write an implementation of the ChatServer class of Section 19.2 that uses a nonstatic version of the data member clientVec. You may do this by making the following changes to Java program of Section 19.2:
In the main of the ChatServer class, pass the server object to the ClientHandler constructor by
ClientHandler clh = new ClientHandler(socket, this);
Add the following additional data member to the ClientHandler class
ChatServer chat_server;
Change the ClientHandler constructor so that it accepts the two arguments shown below:
public ClientHandler(Socket s, ChatServer c) { try { sock = s; chat_server = c; // . . . . .
With all of the above changes, the for loop in the run() method of ClientHandler can be changed to:
for (int i = 0; i < chat_server.clientVec.size(); i++) { ClientHandler cl = (ClientHandler) chat_server.clientVec.elementAt(i); // . . . . . .
Write an applet program that elicits a piece of information from a client viewing the applet and then sends the information back to a server program running at the host that is the home of the applet. This homework is also an exercise in launching a JFrame object from an applet. Your frame should consist of a text-field and a button. When the client clicks the button, the information typed into the text-field should get transmitted back to the server.
Extend the ChatServer class of Section 19.2 so that clients can download a chat applet from your web page. When a new client checks in via the applet, the applet should show all the accumulated chat up to that time in the main applet window. The applet should also include a button that creates a separate window (a popup) for a client to input his/her contribution to the ongoing chat. This separate window should include a submit button that when pressed causes the text entered to show up in the main applet windows of all the participating clients.
|