Windows beans are the primary visual context for other user interface
components. VisualAge provides window beans from the
com.sun.java.swing and
java.awt packages. Although Swing and AWT beans can
be mixed, it is inadvisable.
You can compose and test a window in the Visual Composition Editor.
You should create a new composite bean as a subclass of a window class.
You can also add window beans for secondary windows. A FileDialog
cannot be composed as a primary window bean. It represents a system
file dialog.
- Create one of the following window beans:
Bean
| Description
|
JDialog or Dialog
| A custom dialog, typically a secondary window
|
JFrame or Frame
| A desktop window with a title bar, sizing borders, and sizing buttons
|
JInternalFrame
| A frame that is a child of another Swing component
|
JWindow or Window
| A window without a title bar, sizing borders, and sizing buttons
|
- Creating a window bean
- You can create a composite window bean in any of the following ways:
- From the Quick Start window. Select Quick Start from the
File pull-down menu to open the Quick Start window. Select
Basic in the left pane, Create Class in the right pane,
and the OK button to open the SmartGuide - Create Class
window. Select one of the window beans as the superclass for your
window, and request to compose the class visually. See the related task
topic on Creating a class for details.
- From the Create Class tool bar button. Select the
button on the tool bar to open the SmartGuide - Create Class
window. Select one of the window beans as the superclass for your
window, and request to compose the class visually. See the related task
topic on Creating a class for details.
- Adding a secondary window to a composite bean
- Add a window to the free-form surface of the composite bean.
- For a static window, add one of the window beans.
- For a dynamically created window, add a Factory. From the
Factory's pop-up menu, select Change type. Then,
specify the window bean as the object type. Create the window when an
event occurs by connecting the event to a Factory constructor method for the
window.
- Compose the user interface and logic for the window. Add and
arrange visual components, add nonvisual beans, and connect them to establish
functional relationships.
- Defining a window title
- Enter text for the title property in the window's property
sheet.
- Accessing a JWindow bean in the Visual Composition Editor
- When you create a JDialog, JFrame, or JWindow bean, a content pane is also
added in which to place other components. With the exception of a
JMenuBar, user interface components are added to the content pane.
Because a JWindow has no frame, the content pane completely covers the JWindow
bean in the Visual Composition Editor. To access the JWindow bean, open
the Beans List.
- Resizing or moving a JWindow bean in the Visual Composition Editor
- Select the JWindow bean in the Beans List. Then, you can resize or
move the JWindow in the Visual Composition Editor. If you try to select
the JWindow bean in the Visual Composition Editor, you will select its content
pane instead.
- Replacing the content pane for a JDialog, JFrame, or JWindow bean
- To replace the content pane, delete it and add another container
component. When you delete the content pane, a warning is displayed
indicating that the content pane is missing. If you save the bean
without adding another content pane, a JPanel bean is used.
- Arranging beans in a window
- Use either of the following methods:
- Use a layout manager to control size and position of beans within the
window content pane or client component.
- Without using a layout manager, place beans approximately where you want
them and use visual composition tools to align them.
- Keeping a dialog in focus until it is closed
- Set the modal property to True in the dialog's
property sheet.
- Preventing window resizing
- Set the resizable property to False in the
window's property sheet.
- Opening a window
- Connect an event, such as the actionPerformed event of a button
or menu item, to the window's show()
method.
- Closing a window
- Connect an event, such as the actionPerformed event of a button
or menu item, to the window's dispose()
method.
- Specifying open or save for a file dialog
- Specify the file operation for the mode property in the
dialog's property sheet. Select LOAD for an open
dialog, orSAVE for a save dialog.
- Defining initial selection information for a file dialog
- You can specify an initial directory, file, or both in the dialog's
property sheet. Specify an initial directory name for the
directory property. Specify an initial file name for the
file property.
- Obtaining information from a dialog when it is closed
- Connect the normalResult of the show()
connection to the target property for the information. Then, connect
the dialog property that contains the information to the appropriate parameter
of the normalResult-to-target connection.
For example, if you want to open a dialog to prompt for a name in a text
field and return it to a label in the primary window, do the following:
- Connect an event in the primary window to the
show() method of the dialog.
- Connect the normalResult of the show()
connection to the text property of the label in the primary
window.
- Connect the text property of the text field in the dialog to
the value parameter of the
normalResult-to-text connection.
- Test the window. You can run the window from the Visual Composition
Editor. This makes it easy to iteratively modify and test the window
while you compose it.
- Testing a window from the Visual Composition Editor
- You can test a composite bean that is a subclass of a window bean in the
Visual Composition Editor. Do either of the following to test the
window:
- Select the
button on the tool bar.
- From the Bean pull-down menu, select Run, then
Run main.
VisualAge performs the following steps:
- Saves the edit description of the bean
- Generates source code
- Compiles the class
- Runs the window
For examples, see the CustomerInfo class in the
com.ibm.ivj.examples.vc.customerinfo
package. These examples are shipped in the IBM Java Examples
project.
Working with Beans Visually
Using VisualAge Beans in Visual Composition
Creating a class
Adding the IBM Java Examples project
Window Beans
CustomerInfo Sample
