Exercise

To extend your knowledge of the subjects covered today, try the following exercise.

  1. Create a chat room application. Participants provide their name and can send messages. Participants read messages posted by all other participants.

To assist you in this task, three Java files have been provided in the exercise sub-directory for Day 9 on the accompanying Web site.

The Chat.java and ChatDisplay.java files are complete and need not be edited. These files provide the Swing code to enter and display the chat room messages on the screen.

The TopicServer.java is a starting point for you to further develop the chat server. The initial code simply uses the callback method addMessage to bounce the message back to the screen. The addMessage method uses the interface defined in ChatDisplay.java.

You should edit this file to replace this callback with code to publish the message to a topic. You will then add a subscriber that consumes messages from this topic and displays them on the screen. You add your message to the message box at the top and click Send. The message should then appear in the Bulletin Board window of all Chat programs running.

Add a property called From to the message and set it to the from parameter passed in. This will then be displayed in the chat room window.

A completed TopicServer is included in the solutions sub-directory of Day 9 of the case study. To run the solution, go to the solution directory for Day 9 and type:

asant Chat

Note that you will need to create the JMS resources using asant create-jms (if you haven't already done so as described in the section “Using JMS with the J2EE RI”).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.10.153