Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Release your inner poet: Use servlets to create a collaborative poetry app

Add two facilities for collaboration to an otherwise humdrum applet

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
I'm sure most of you have seen magnetic poetry, that refrigerator-magnet word game whereby you arrange individual word magnets into poetic musings. You may have even unearthed an applet version of this game during your online adventures. The applet presents a selection of words in the form of electromagnetic tiles that you drag around with your mouse.

Although the poetry game is quite fun, the applet actually represents outdated, mid-90s technology. To bring the applet up to date we're going to add a collaborative touch. In fact, this month we'll add two facilities for collaboration.

Note, though, that our creation requires the most robust of Java virtual machines. Our tests indicate the poetry applet works for the following platforms:

  • AppletViewer on Solaris
  • HotJava on Solaris
  • Microsoft Internet Explorer 4.0 on Solaris
  • Microsoft Internet Explorer 4.0 on Windows 95/NT
  • Netscape Communicator 4.04 (with JDK 1.1 support) on Solaris
  • Netscape Communicator 4.04 (with JDK 1.1 support) Windows 95/NT


Click here to view the applet.

The poetry applet



Offline collaboration
You've whiled away your day at work, channeling all your energy into a masterful outpouring of poetic expression. Now, how do you share this feat with the world? You can write it down and print it out, or -- with our New TechnologyTM -- you can submit your work to the poetry servlet!

The poetry servlet is a simple database of submitted poems; you can either submit your own poem or browse through the poems submitted by other creative geniuses.

Online collaboration
Simply being able to read what someone else has written often is not enough. Sometimes two heads work better than one. For this multiple-poet situation, we want realtime collaboration so that many people can come together and produce something better than any one of them could have done alone. Again, our New TechnologyTM can help!

Using the distributed list classes that we introduced with the earlier whiteboard articles, we can add online collaboration to the poetry applet. By storing the state of the poetry board in a distributed list, we can truly share the poetic experience.

The collaborative poetry framework

Our collaborative poetry application naturally is divided into client-side and server-side components. Let's take a look at what each of these entails.

The collaborative framework

Client side
The client side of the poetry application features one main class, PoetryBoard, which implements the click-and-drag poetry board -- the basic user interface through which poetry is created.

Every tile on this board is represented by the Tile class. Tile is a serializable stateholder that stores a word plus its color and location, and provides the actual tile drawing code. We're making the class serializable because we need to use the object streams for communication purposes.

Finally, the actual poetry applet is implemented with the PoetryApplet class. This creates and controls a PoetryBoard, which provides client-side networking with the poetry servlets, and the user interface facility for engaging online collaboration, and loading and saving poems.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Pure CGI-based magnet-style poetry
  • http://prominence.com/projects/poetry/
  • http://asterisk.reshall.berkeley.edu/poetry/
  • http://queue.IEOR.Berkeley.EDU/~andryan/fridge/
  • Pure non-computer-based magnet-style poetry http://www.magpo.com/
  • The JavaSoft Servlets page, including the Servlet Development Kit (JSDK) http://jserv.javasoft.com/products/java-server/servlets/
  • The JavaSoft Java Web Server page, a great Webserver for developing servlets http://jserv.javasoft.com/products/java-server/webserver/
  • Jigsaw, a free pure-Java Webserver that also supports servlets http://www.w3.org/Jigsaw/
  • Download the complete source as a gzipped tar file http://www.javaworld.com/javaworld/jw-04-1998/step/jw-04-step.tar.gz
  • Download the complete source as a zip file http://www.javaworld.com/javaworld/jw-04-1998/step/jw-04-step.zip
  • Download Netscape's JDK 1.1 support patch for Windows 95/NT and some flavors of Unix http://developer.netscape.com/software/jdk/download.html
  • Previous Step by Step columns