CS 202 - Computer Science II - Spring 2006
Lab 6 - Swing GUIs
Loyola College >
Department of Computer Science >
Dr. James Glenn >
CS 202 >
Labs >
Lab 6
Due
Wednesday, March 22nd at 11:59pm.
Labs submitted one day late will be assessed a
20% penalty. Labs will not be accepted more than one day late.
Objectives
- to create Swing components
- to use layout managers
- to create listener objects
Reading
Anderson & Franceshi, Chapter 12
Assignment
As of 11:25am 3/16/2006 there is a server running on gunpowder.cs.loyola.edu at port 4501.
This applet should be able to connect to that server.
Complete the code for the GUIChatClient class. You will have
to delcare and instantiate the components, arrange them in the panels,
and write, instantiate, and register the listener classes and objects.
Files
Start with the code in the
incomplete version of GUIChatClient.java.
Advice
- Start by declaring and instantiating the components and adding them to the
appropriate panels. Then add the panels to each other or to the
content pane of the application. You can run the application at
this point to check the arrangements of the components. If some
components are stretched in ways they shouldn't be, check the
position at which you're adding them.
- Once the layout is satisfactory, set any attributes of the components
and register the listeners. To test, you can create listener classes with
stub methods for actionPerformed that simply use
System.out.println to display a message (so you will know
the events are being sent to the right listeners).
- Finally, add the code to the listeners' event handler methods.
Remember that any components you need to use by name in the
event handlers should be declared as fields. Make sure you are
not shadowing any of the fields by redeclaring them in the
constructor.
Exercises
Do two of the following three exercises.
- Suppose we wish to add the ability for users to send private messages
to another user of the chat room. What additional components would we
have to add to the interface? Draw a diagram showing the existing
panels and any new panels you would create, indicating the location
of the new components.
- In addition to the additional components needed to allow private
messages, the protocol used to communicate between the server and
the client would need to be updated so that the server could
distinguish the private messages from the public messages. Discuss
how the protocol could be changed and implemented.
- All of the messages in our chat system go through a central server,
which could store a transcript of everything that was said. Is
keeping such a transcript a good idea or a bad idea? Discuss the
ethical implications.
Submissions
Submit the source code (.java file) for your completed GUIChatClient class.