Class NetLibs.NetLibs
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class NetLibs.NetLibs

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----java.applet.Applet
                                   |
                                   +----NetLibs.NetLibs

public class NetLibs
extends Applet
implements NetLibsConst, CommandListener
NetLibs is a sort of game which generates silly stories. It is loosely based on Mac Libs which is a more sophisticated Macintosh version, and that is loosely based on the old Mad Libs books.

The user can choose from several story templates and then generate a story automatically by retrieving the words from predefined dictionaries, or by typing the words in a form. The templates contain prompts which correspond to certain word categories such as noun, verb, adjective, etc. Each category has its own dictionary file containing words. When the story is generated automatically, the prompts are used to find the categories and then choose a word at random. When the user is typing the words in a form, the prompts appear next to a text field to show the user what type of word is needed. After all words are chosen, the story template is scanned and the prompts are replaced by the chosen words. The resulting story is then displayed in the window.

The story template files refer to the prompts by putting the index in angle brackets like this:

		One day, <1> went to the <2>.
This enables the same word to appear in different places in the story.

The template files all end with the ".txt" suffix and have a corresponding prompt file with the same name and the ".prompts" suffix. In the prompts file, each prompt is on a line separated by a 'new line' character. The number in the angle brackets in the template correspond to the line number in the prompt file (starting at 1).

The prompts in the prompt file consist of the name of a dictionary file without the ".words" suffix. There are also currently two special ways prompts can be used. To generate a random number, a prompt like this can be used:

		number from 1 to 100
Also, any prompt can begin with a captial letter. In that case, the chosen word will automatically be capitalized.

The word files all end with the ".words" suffix. Each word is on a line separated by a 'new line' character. When a random word is selected, the appropriate word file is read in and the words are separated into a vector. Then a random number is generated to select the nth word. The word vectors are cached, so if a story template requests 5 nouns, the word file will not be read and scanned 5 times. Also, if you generate another story with the same template, it will be much faster the second time.

Note: In the Macintosh version ("Mac Libs"), the user can create and edit templates and dictionaries. Templates and the resulting stories can contain formatted text and graphics. Also, the prompts can reference properties and rules. The rules can be implemented in the dictionary in a HyperCard-like language. For example, the "verb" dictionary has rules for "past_participle", "present_participle", etc. This eliminates the need to have separate dictionaries for each type.

Author:
Michael Benson

Constructor Index

 o NetLibs()

Method Index

 o action(Event, Object)
Overrides the action method in Component to check for button clicks.
 o autoGenerateStory()
Generates a story automatically from the dictionaries.
 o commandSelected(int)
This is a "listener" which is called whenever a command is selected.
 o getNetLibsCommand()
Get the NetLibsCommand object to issue a command.
 o init()
NetLibs initialization.
 o promptGenerateStory()
Generates a story by prompting the user for words.
 o substituteWords(String, Vector)
Gets the story template and substitutes the chosen words into the story.

Constructors

 o NetLibs
  public NetLibs()

Methods

 o init
  public void init()
NetLibs initialization. Creates main applet frame. Fills the Story Templates choice box by reading the file "templates.prompts".
Overrides:
init in class Applet
 o getNetLibsCommand
  public NetLibsCommand getNetLibsCommand()
Get the NetLibsCommand object to issue a command.
Returns:
the NetLibsCommand object.
 o action
  public boolean action(Event evt,
                        Object arg)
Overrides the action method in Component to check for button clicks.
Parameters:
evt - the event that caused the action.
arg - the action.
Returns:
true if the event has been handled; false if not.
Overrides:
action in class Component
See Also:
action
 o autoGenerateStory
  public void autoGenerateStory()
Generates a story automatically from the dictionaries. Reads the prompt file, gets a random word from a dictionary for each prompts, then substitutes the words into the story.
 o promptGenerateStory
  public void promptGenerateStory()
Generates a story by prompting the user for words. Reads the prompt file, then opens the prompt window. When the user clicks "OK" in that window, the words will be substituted into the story.
 o substituteWords
  public void substituteWords(String storyName,
                              Vector strings)
Gets the story template and substitutes the chosen words into the story.
Parameters:
storyName - the name of the story template.
strings - the list of words to be substituted into the story.
 o commandSelected
  public boolean commandSelected(int command)
This is a "listener" which is called whenever a command is selected. It is used for doing things like updating buttons, menu items, etc.
Parameters:
command - the command which was executed.
See Also:
NetLibsConst

All Packages  Class Hierarchy  This Package  Previous  Next  Index