Dialog wizard

This is a feature of JBuilder Professional and Enterprise.

The Dialog wizard creates a new class that can extend either the Dialog class, or the JDialog class, and adds it to the current project. It adds header information to the class from the project file and adds the necessary import statements. It also does the following:

To open the Dialog wizard, choose File|New, then double-click the Dialog icon.

The wizard contains the following fields:

Package

Displays the package name derived from the project file. To assign a different package name to the file, click in the Package field and type in the new name.

For more information on packages, see the "Packages" topic in the "Creating and managing projects" chapter of Building Applications with JBuilder.

Class Name

Displays the default name assigned to the dialog class. To rename the class, click in this field and type in a new name.

Base Class

Displays a drop-down list box to select the class from which you want to inherit. Click the ellipsis button to bring up a browser if you want to search for a base class that is not included in this drop-down list.

Options

Generate Header Comments

Uses information from the project file as header comments at the top of the application class file. This is the information entered in the Project wizard when creating the project file.
//Title:        Your Product Name
//Version:    
//Copyright:    Copyright (c) 1997
//Author:       Your Name
//Company:      Your Company
//Description:  Your description

See also:
Creating and using dialogs


Creating and using dialogs

When making a new dialog, you should consider whether you want to make it into a Java Bean that can be placed on the component palette. If so, there are specific additional requirements that you must consider.

But, even without making your dialog into a bean, you can create it and use it in JBuilder.

Creating a new dialog

To create a new dialog, use the Dialog wizard. After finishing the wizard, you can use the UI designer to add buttons and other controls to the panel that was placed in the new dialog class.

Using a dialog that is not a bean

Once the dialog has been created and its UI designed, you will want to test or use your dialog from some UI in your program.

To do this,

  1. Instantiate your dialog class from someplace in your code where you have access to a Frame which can serve as the parent Frame parameter in the dialog constructor. A typical example of this would be a Frame whose UI you are designing, that contains a button or a menu item which is intended to bring up the dialog. In applets, you can get the Frame by calling getParent() on the applet.

    For a modeless dialog (which we are calling dialog1 in this example), you can use the form of the constructor that takes a single parameter (the parent Frame) as follows:

    Dialog1 dialog1=new Dialog1(this);

    For a modal dialog, you will need to use a form of the constructor that has the boolean modal parameter set to true, such as in the following example:

    Dialog1 dialog1=new Dialog1(this, true);

    You can either place this line as an instance variable at the top of the class (in which case the dialog will be instantiated during the construction of your Frame and be reusable), or you can place this line of code in the actionPerformed() event handler for the button that invokes the dialog (in which case a new instance of the dialog will be instantiated each time the button is pressed.) Either way, this line instantiates the dialog, but does not make it visible yet.

    (In the case where the dialog is a bean, you must set its frame property to the parent frame before calling show(), rather than supplying the frame to the constructor.)

  2. Before making the instantiated dialog visible, you should set up any default values that the dialog fields should display. If you are planning to make your dialog into a Bean (see below), you need to make these dialog fields accessible as properties. You do this by defining getter and setter methods in your dialog class.

  3. Next, you have to cause the dialog to become visible during the actionPerformed() event by entering a line of code inside the event handler that looks like this:
    dialog1.show();

  4. When the user presses the OK button (or the Apply button on a modeless dialog), the code that is using the dialog will need to call the dialog's property getters to read the user-entered information out of the dialog, then do something with that information.

To see examples of using modal dialog components (dialogs that have been wrapped as Beans, with default constructors), see the tutorial, "Building a Java text editor."