How It Was Done ...![]() | ||||
![]() |
Client side The PixelToy applet logically consists of several classes - a reader, writer, pixel array, canvas, palette, and applet. However, to decrease downloading time, I grouped all these classes into a single PixelToy class. The resulting .class file is about 12K. The hardest part of writing the applet was working around all the bugs in AWT (the Java GUI library). In the end I decided to draw all the user-interface elements myself, using low-level commands like drawImage() and fillRectangle(). I think the resulting interface looks nicer than an AWT-based interface would look anyway. Server side The server is a fairly standard multithreaded server written in Java. I use two threads for each client (reader and writer), which prevents the server from blocking while writing to a slow client. Communications When the PixelToy client starts up, it opens a connection to the PixelToy server and sends a packet asking the server to send it a picture. When it receives the picture from the server, it makes an image out of the picture and displays the image. Client -> Server Request picture Client <- Server Send picture: color1, color2, ... colorn After that, each time a user releases the mouse button at the end of a brush stroke, the client sends the current color and the x,y coordinates of the pixels affected by the brush stroke to the server, which then echoes the brush stroke to every applet that's connected. Client1 -> Server Pixels: color, count, x1,y1, x2,y2, ... xn,yn Client1 <- Server Pixels: color, count, x1,y1, x2,y2, ... xn,yn Client2 <- Server ... Clientn <- Server Download the source Source code for PixelToy is available under the GNU Public License. | |||
![]() | ||||
Brian Slesinsky hacks Java and CGI scripts at HotWired. He prefers restaurants where the table settings include crayons. | ||||
Previously in Demo ...
Copyright © 1996 HotWired, Inc. All rights reserved. |