CS102 Code Examples
These are some of the longer code examples from lecture.
- Picture.java
- A subclass of Component for displaying an image from a file.
- FreeFormLayout.java
- A layout manager that basically does nothing.
- Client/Server Framework:
The first two files provide a framework for creating client/server
applications that is slightly more
general than the one given in class. Adapters are provided for both the
ClientBehavior and ServerBehavior interfaces. All ClientBehavior and
ServerBehavior objects are responsible for calling closeSocket
when they are finished. The second two files provide an example.
- Client.java is a general client that
uses a ClientBehavior object to define how the client should interact
with the server through streams.
- Server.java is a general server that
uses a ClientHandlerFactory to create a new Thread to service each client.
- SquareClient.java is an example client that displays
a textfield in which you can type numbers that are squared by the server.
The example goes a bit overboard on the use of anonymous classes.
- SquareServer.java is the companion server for the example. Again, anonymous classes are used heavily.
- ReflectionExample.java
- includes some demonstrations of using reflection to examine classes,
instantiate objects, and call methods on objects.