Java Reference
In-Depth Information
the invocation of alarmAction( ) . Test your class with code that increments and
prints out a counter.
3. Write a GUI program that animates a four-colored “beach ball” in place by rotat-
ing the colors. The beach ball can be drawn as a solid circle with four different
colors in each of the four quadrants of the circle. Use a thread to rotate the colors
every quarter second.
4. Modify the GUI in Display 19.2 so that the circles are alternately red, white, and
blue, and so that they fill the area from bottom to top instead of top to bottom.
5. Produce a GUI similar to the one in Display 19.2 except that instead of filling
an area with circles, it launches a ball (which is just a circle) and the ball bounces
around inside a rectangle. You can create the illusion of a moving ball by repeatedly
erasing the ball and redrawing it at a location a little farther along its path. Look
up the method setXORMode in the class Graphics . It will take care of the erasing.
6. This project shows how to create a simple Web server. Create a server program that
listens on port 8000. When a client connects to the server, the program should
send the following data to the client,
VideoNote
Solution to
Programming
Project 19.3
"HTTP/1.0 200 OK\n\n" + body
where body is the String "<HTML><TITLE>Java Server</TITLE>This web
page was sent by our simple <B>Java Server</B></HTML>" . If you know
HTML, feel free to insert your own content. The header line identifies the message
as part of the HTTP protocol that is used to transmit Web pages.
When the server is running, you should be able to start a Web browser and
navigate to your machine on port 8000 and view the message. For example, if the
server is running on your local machine, you could point your Web browser to
http://localhost:8000 and the message in body should be displayed.
7. Modify the server from Programming Project 19.6 so that the content for body
is read from a file on the local hard drive instead of hard-coded into the program.
This file should contain the HTML string from Programming Project 19.6. In
addition, modify the server so that a new thread is created for each connection.
Test the server by starting up two or more Web browsers and navigate to your site.
Each browser should display the message.
8. Create a threaded chat server and a corresponding chat client. Using the port of
your choice, create a server that starts a new thread for every client that connects to
it. Every message that the server receives from a client should be broadcast back to
all other clients. The chat client should allow the user to type in a string of text and
have it sent to the server upon pressing enter. Use threads on the client so messages
can be retrieved from the server and displayed even while the user is typing. Test
your server by connecting to it with multiple clients and verifying that messages
are transmitted back and forth.
Search WWH ::




Custom Search