- No interest in actions for MenuBar and Menu - only in MenuItem.
- Define a new subclass of MenuItem, MenuButton with one method action()
public boolean action(Event evt, Object what) {
return false;
}
- Subclass menu buttons from this, with application logic in action()
class QuitButton extends MenuButton {
public boolean action(Event evt, Object what) {
System.out.println("Exiting...");
exit();
return true;
}
}
- Override Frame action() only enough to invoke action() method on subclasses
of MenuButton
public class MyFrame extends Frame {
public boolean action(Event evt, Object what) {
if (evt.target instanceof MenuButton) {
return ((MenuButton) evt.target).action(evt, what);
} else {
return super.action(evt, what);
}
}
}