The client is a Java applet, designed to run inside of a WWW browser. The ability to write applets is one of the strengths of Java that is exploited by Qchat. The ability to run Java applets within a WWW browser has become standard on many browsers, most notably Netscape Navigator and Microsoft's Internet Explorer. The availability of these browsers for many platforms automatically makes Qchat available on all of those platforms. This simplifies the coding process; instead of writing and debugging a new version for every platform, one version can be written that runs on every platform. The operating system independence of Java applets is one of their main strengths.
The use of a Java applet for the client also assures the user that their system remains secure. Java applets have no ability to access the local file system on the machine that they run. This allows users to run Java applets without fear of viruses. The applet could have been designed as a Java program, but this would defeat the purpose of integrating Qchat with the WWW.
The Qchat client applet uses the standard Java classes provided by Sun to maintain compatibility across all implementations of Java. The client uses four main components of Java to accomplish its task, the Applet class, the Thread class, the Socket class and the Abstract Windowing Toolkit. These classes provide the foundation upon which the client is built.
The Applet class is the base for all applets. It provides the ability to read in parameters passed to the applet through a web page, and permits the code to run within a browser. Within the applet's frame of reference (the screen area in the web page given to it by the browser) any graphical Java code can be used. To simplify the creation of Java applets, Sun has provided the AWT to assist in the development of consistent user interfaces.
The most visible class (to the user) is the AWT. This set of classes provides the means to create and display the user interface of the client. The AWT provides a layer of machine and operating system independent routines used to create user interface components and connect them to the rest of the applet. The components used in the client include buttons, text display areas, selectable lists, text entry fields, and labels. These components are arranged on the client display according to the gridbag layout manager provided by Java. This layout manager allows extremely flexible displays to be created that automatically resize the components based on the size of the display area. The flexibility of the gridbag layout allow the client applet to be used on systems with different resolutions without adjusting the code.
A screenshot of the applet is provided to show the layout and positioning of the components in Figure 4.1. On different systems the display may vary from the one pictured in the screenshot. However, every modern windowed operating system provides the same basic components used to build the applet. The main focus of the applet is the message display area. This is a text area used to display messages from users and the server. Unfortunately Java does not provide a built-in methods to control word-wrapping and scrolling. To implement these features code was added to the display area to produce the desired effect. The text entry field directly below the message area is where messages are entered to be sent to other users. The text typed in this field is forwarded to the networking code that sends the message to the server for distribution to other clients. The lists and their associated text entry fields and buttons control the channels and users. The channel list displays the current number of users in each channel and allows the user to select a channel to join. The text entry field above the list provides an area to enter new channels to be created. The user list and its buttons allows the user to filter out unwanted users. It also displays the status of users. If a user is being filtered their name is followed by - Filtered. The two remaining buttons allow the user to query the server for a status check and to clear the message display area and the message entry area.
The Thread and Socket classes are used in conjunction to provide network communication for the client, while maintaining an interactive user interface. The Socket class provides a standard port for accessing the network, allowing the client to write and read from the network as easily as from a terminal. The Thread class is used to assure that the user interface does not stop while waiting for information from the network. This multithreaded approach uses one thread to handle the display, while another thread waits for and interprets information from the network. The information read from the network is then passed to the display function to update the user interface.
Java, and therefore Qchat, is an event driven language. In the client there are two types of events that must be handled. The first type is events initiated by a user action, including button clicks and text entry. The result most user events is to send a section of information out over the network to the server, and to update a portion of the display. An example is hitting enter after typing a line of text in the message entry area. This text is displayed in the message display area, and encapsulated in the Qchat protocol before being sent over the network to the server. This process is typical of most user actions. The second type of event is network initiated. These events occur when information is received over the network from the server. The result of these events is to update the users display to reflect the new information. An example is text arriving from the server that has been sent from another user. The text is extracted from the Qchat protocol and displayed in the message display area.
Several problems arose during the implementation of the Qchat client. The first involved the use of the gridbag layout manager. Although this layout manager is extremely flexible, it is difficult to understand how it works. Some trial and error was necessary to obtain a good user interface. The other problems were with the message display area. Java 1.02 does not provide word wrap or program controllable scrolling for text areas. Both of these items had to be implemented to provide an easy to use chat environment. With the release of Java 1.1, these problems may have been resolved.