Java Reference
In-Depth Information
The help file is opened using a
FileReader
that is wrapped in a
BufferedReader
.
Since the help file contains text, using a character stream allows the Help system to
be more efficiently internationalized.
The
helpOn( )
method works like this. A string containing the name of the topic is
passed in the
what
parameter. The help file is then opened. Then, the file is searched,
looking for a match between
what
and a topic in the file. Remember, in the file, each
topic is preceded by a #, so the search loop scans the file for #s. When it finds one, it
then checks to see if the topic following that # matches the one passed in
what
. If it
does, the information associated with that topic is displayed. If a match is found,
helpOn( )
returns
true
. Otherwise, it returns
false
.
5.
The
Help
class also provides a method called
getSelection( )
. It prompts the user for
a topic and returns the topic string entered by the user.
This method creates a
BufferedReader
attached to
System.in
. It then prompts for
the name of a topic, reads the topic, and returns it to the caller.
6.
The entire disk-based Help system is shown here: