Java Reference
In-Depth Information
boolean result = true;
try {
int integer = Integer.parseInt(datum);
} catch (NumberFormatException e) {
result = false;
}
if (result) {
feedbackLabel.setText(datum + " is an integer");
}
else {
feedbackLabel.setText(datum + " is not an integer");
}
}
});
10.5.3
Generating getter/setter methods for fields bound to data
If you have a JavaBean class whose properties should be bound to controls on
your GUI , you can integrate these properties by making changes to the underly-
ing form class. For example, you may have a JavaBean with five String properties
and a GUI with five text fields that are designed to show the bean's values and, if
the user edits that data, set new values in the bean. You can accomplish this by
editing the underlying form class, hooking in each of the getters and setters to
draw from and persist to the bean. This pattern, however, is common enough in
GUI implementation that the GUI Designer provides an additional control to
handle the binding for you. It's called the Data Binding Wizard.
Once you've bound a form to an underlying form class, click the Data Binding
Wizard button on the GUI Designer's toolbar. The wizard process prompts you to
choose to bind to an existing bean or to create a new one. You're then prompted
to select the property of the bean that should be bound to the GUI component.
All integration work, imports, and so on are taken care of for you. Running the
wizard on a component also allows you to sever the binding or reapply it to a dif-
ferent location.
10.5.4
Invoking your form
When you want to invoke your form class within your application, construct an
instance of the class, place your form's top-level panel into a JF rame (just as you
would normally do with a panel you created by hand), and invoke it. Listing 10.3
shows a typical example, using the main() method as a starting point.
 
 
 
 
 
 
 
Search WWH ::




Custom Search