The Name attribute is particularly useful in writing Action handling routines in which a reference to the target is not known ahead of time. Such Action handlers are often generated by GUI builders. Previously, these routines tried to identify the target Component by looking at its label string. This approach fails when the label strings are localized. The following example shows the Name attribute used by an Action handler.
public boolean action(Event event, Object arg) {
String targetName = event.target.getName();
if( targetName.equals("OKButton") ) {
// Handle OK button press.
return true;
} else if( targetName.equals("CancelButton") ) {
// Handle Cancel button press.
return true;
} else {
return false;
}
}
The Locale attribute of Component allows the GUI (or portions of the GUI) to maintain its own default locale. This would be useful, for example, for an applet that used the Japanese locale even when the rest of the browser was using the USA locale.