OUTPUT - Write to a Dialog box

The Db.class allows you to write to a dialog box in prefedrence to writing to the screen, i.e. in preference to writing to the terminal window on the Unix system or to the Command Prompt window on the Microsoft XP system.
To import this output library class you need to type the import instruction
import flanagan.io.*;
at the top of your program.

A number, character, boolean or String may be displayed using the statement
     Db.show("The value displayed is ", arg);
where arg may be a double, a float, an int, a long, a boolean, a char or a String and the message "The value displayed is " may be replaced by whatever message you wish to display.

The statement
     Db.show("The value displayed is ", arg, trunc);
where arg may be a double or a float will truncate the number of decimal places displyed to trunc, where trunc is an integer.

Ending your program
If you open a window, and opening a dialog box is opening a window, you must close your program with a specific command. The most convenient way is to make the last line of your program the statement
    Db.endProgram()
This command will check that you do wish to end your program. The command
    System.out.exit(0)
will end your program without any check.

Example Program
The Db.show method is illustrated in the following example program:

/*          DbOutputExample
            Illustrates output via a dialog box
            Michael Thomas Flanagan
            27 May 2005
*/

import flanagan.io.*; / imports the Db class

public class DbOutputExample{

      public static void main(String[] args){

            double xValue = 1.23456789D;

            // output a double
            Db.show("The value of xValue is ", xValue, 4);

            // End program
            Db.endProgram();
      }
}

The output of this program is

Further details
Details of the java output library Db may be found on Db class
Details of the Michael Thomas Flanagan's total input library may be found on Input and Output Classes
Details of the Michael Thomas Flanagan's full library may be found on Michael Thomas Flanagan's Java Library




Return to Db Class documentation
Return to Java Langauge - Undergraduate Notes - main page