Java Reference
In-Depth Information
FIGURE 12.1
Swing user interface.
The JFC is an event-driven model. Once you create the main window and pop-
ulate it with GUI elements, the program operates by reacting to the various events
for which you have registered interest. The way you show interest is to implement
listener interfaces and attach the listener to GUI elements. For example, you might
code an ActionListener and attach it to a button. When the button is clicked, the
actionPerformed() method in your listener is called with information about the
event. To understand how to do all this, you should go to the Java Sun Web site and
find the tutorials on constructing GUIs.
P ROPERTIES F ILES
In many environments where COBOL is used, important runtime information ex-
ists outside the program. Most of the time, the actual file names that are the target
of execution and other parameters to control execution are defined in job control
language and passed to COBOL by the operating system. This allows the same pro-
gram to be used with different files, such as test and production files, or with vari-
ous execution options, without having to recompile the program.
One alternative for a Java program is to use command-line arguments. This can
become quite cumbersome if the number of arguments becomes extensive. Not
only do you have difficulty editing the command line, you also have the problem of
parsing and interpreting the arguments on the program side.
A better alternative is a properties file. In a Java environment, a properties file
is often used to supply this runtime information. A properties file is simply a text file
that consists of name-value pairs separated by the equals (=) operator. It is much
like a Hashtable written in text and, in fact, the Properties class that you use to read
and write the properties file extends Hashtable . Here are the contents of a simple
properties file:
Search WWH ::




Custom Search