![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]()
|
![]() ![]() ![]() ![]() |
![]() |
|
|
|
![]() |
|
FormField HelpHelp is available for each task, or you can go straight to the FormField source code to see a solution.Task 1Declare the abstract class FormElement to be a subclass of Panel so that it can act as a Container.
public abstract class FormElement extends Panel { ... } Task 2Define the method public boolean isEmpty to return false.
public boolean isEmpty() { return false; } Task 3Define an abstract method public String getContents.
public String getContents(); Task 4Define the method public void verify to do nothing.
public void verify() {} Task 5Define method public boolean handleEvent. Upon LOST_FOCUS or ACTION_EVENT events, it should call verify on the element itself unless the element is empty.The event convenience methods are called by method handleEvent. For example, action is called when an event of type ACTION_EVENT occurs. When a Component loses the focus (that is, the user clicked outside the Component), a LOST_FOCUS event is generated. You can override handleEvent to trap these two event types.
public boolean handleEvent(Event event) { switch (event.id) { // if they click mouse outside of element or activate it, // verify the element. case Event.LOST_FOCUS: case Event.ACTION_EVENT: if ( !isEmpty() ) verify(); return true; default: return super.handleEvent(event); } } Any other event should be delegated to the standard handleEvent--call super.handleEvent to force the system to continue as if this handleEvent method had never intervened. |