addComponentAttributes
, addFrameAttributes
,
and addDialogAttributes
should be called in the
constructor to add a set of forwarded attributes to the group.
getOnGroup
and
setOnGroup
. Any attributes that are not handled should
be passed up using a call to super.
You may call super.setOnGroup
with an attribute, even if
the attribute is already being handled by your setOnGroup
method. This will cause the attribute value to be stored in the
group's list of attributes. Then, the getOnGroup
method
will automatically look up this attribute's value from the list.
So make sure that any attributes that are handled in
setOnGroup
without calling super are also handled in the
getOnGroup
method.
initRoot
must be overridden to initialize the root of
the application. The root contains all the children that are
contained by the group. The default generated group contains an
initRoot
method that does the right thing.
startGroup
and stopGroup
methods can
be overridden to get notification when the applet starts and stops.
Also startGroup
will be called when standalone
applications are completely done initializing. This can be useful if,
for example, you want to do something that may cause an error, and you
want to immediately display an error dialog box.
handleMessage
and handleEvent
methods should be overridden to receive AWT events from the root
children. For AWT events, the target of the message is the shadow
corresponding to the AWT component that sent the event. The target of
the AWT event is (of course) the AWT component itself.
For AWT components that do not have a shadow, the target of the message will be set to the AWT component itself.
setOnGroup
and getOnGroup
methods will not
be invoked until the group has been initialized. When the group is
initialized, setOnGroup
will be invoked for all the
attributes.
However, any custom methods that you write need to handle the case of
the group not being initialized or created. This is not a problem if
the user of the group is careful not to call the group's methods until
it is initialized-but better safe than sorry. Dealing with the group
not being initialized almost always consists of doing a null check on
the gui
instance variable.
getOnBody
and
setOnBody
methods in the shadow class where they are
declared (attributes flagged with NONBODY
are the
exception to this rule).
getOnBody
and setOnBody
should invoke
super for all attributes that aren't handled in that particular shadow
class.
Both shadows and groups can be imported into the palette of GUI builder. For information on how this can be done, see Accessing AWT Methods for Shadows Classes.
Another method for adding an AWT component is to use the Generic Component. The Generic Component is a special component that you can use to import any custom AWT component class that you write. See Adding Custom Components and Windows for a discussion of Generic Component.
Main
// Construct the group Group group = new MyFancyGroup(); // Set the group environment. The "args" are command // line arguments. group.setEnvironmentInfo(null, args); // Initialize the group group.initialize(); // Set the top level on the group WindowShadow win = (WindowShadow)group.getWindow(); if (win instanceof FrameShadow) { win.createBody(); group.setTopLevel((Frame)win.getBody()); } else { group.setTopLevel(/* Pass in an existing frame window from your application */); } // Create the group group.create(); // If the group is a panel group, add it in the // hierarchy somewhere if (group.getPanel() != null) { myApplicationFrame.add((Panel)group.getPanel().getBody()); } // Start the group group.start();
Applet
// Construct the group Group group = new MyFancyGroup(); // Set the group environment. The "applet" must be available here. group.setEnvironmentInfo(myApplet, null); // Initialize the group group.initialize(); // Set the top level on the group WindowShadow win = (WindowShadow)group.getWindow(); if (win instanceof FrameShadow) { win.createBody(); group.setTopLevel((Frame)win.getBody()); } else { // Figure out the applet's frame Component comp = applet; while (comp != null && !(comp instanceof Frame)) comp = comp.getParent(); group.setTopLevel((Frame)comp); } // Create the group group.create(); // If the group is a panel group, add it in the // hierarchy somewhere if (group.getPanel() != null) { myApplet.add((Panel)group.getPanel().getBody()); }
The start, stop, and destroy methods should be forwarded from the applet to the group:
group.start(); group.stop(); group.destroy();
See also: