The Console User Interface


The JDO Learning Tools described so far do not provide an interactive user interface. The next two programs in the JDO Learning Tools use a simple console user interface. Although the workings of this console interface are incidental to the purposes of this book, the interface is also unfamiliar to you. This section gives you an idea of what the console interface is like. It also gives you an idea of how you can modify the programs that use it.

When the interface comes up, it prompts you with two lines:

 enter command: --> 

You can control the configuration of the prompt by modifying the properties in the package.properties file found in the com/ysoft/jdo/book/common/console directory. The default configuration works well for highlighting the user's input in the listings provided in this chapter.

There are only three things to remember about the console interface. One, it will not do anything unless you enter a command. Two, every program has at least two commands, quit and help. The quit command terminates the program. The help command lists all of the commands, except help, that the program recognizes. Three, if you enter a command string that the interface does not recognize, it outputs a question mark and prompts again, as the following interaction shows:

 enter command: --> whatever ? enter command: --> 

Some of the command strings are wordy. In some cases, there is more than one command string that will activate the command. The additional command strings provide flexibility in activating a command. For example, the command string

 add data object 

may have the additional command strings

 add add object 

There are only two ways to tell what the additional command strings are. Either try something and see if it is accepted, or look at the source code.

Each command is implemented in a separate class that extends the base class Command, which is found in the com.ysoft.jdo.book.common.console package. In the constructor for the derived command class, there is a call to the super constructor of Command. One of the parameters to this constructor is a list of command strings. For example, the Add command in the Library program has the following constructor:

 public Add(UIClient c)    {    super(c, new String[]          {          "add data object",          "add",          "add object",          });    } 

Any of the command strings activate the command. The first one is the preferred command string, and for that reason, it is shown in the help listing. If you want, you can add more command strings to any command. Within the application, each command string should be unique.

When you enter a command, you may be prompted for command parameters. Often you cannot get out of the command without entering the additional information. Since no lives are at stake, enter something to make the interface happy.

The command classes are package-level classes contained within the source file for the public application class. For example, the source file Library.java contains the source for the public class Library, and also the source for all of the command classes, such as Add, Delete, and Find. Adding additional commands is easy. Pick a command class that is close in behavior to what you want, then copy, paste, and modify. Don't forget to add an instance of the new class to the application's list of Command objects.




Using and Understanding Java Data Objects
Using and Understanding Java Data Objects
ISBN: 1590590430
EAN: 2147483647
Year: 2005
Pages: 156
Authors: David Ezzio

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net