framework
Class Controller
java.lang.Object
framework.Controller
- All Implemented Interfaces:
- java.awt.event.ActionListener, java.util.EventListener
- Direct Known Subclasses:
- FileMenuController, HelpMenuController
public abstract class Controller
- extends java.lang.Object
- implements java.awt.event.ActionListener
Base class for many controllers.
The controller component receives commands from the
GUI and executes them. Programmersneed to seek a
balance between a centralized controller and controllers
for each use case.
Note: This controller only works for ActionEvent
Example:
public class MyController extends Controller {
public MyController(AppWindow aw) {
super(aw);
// etc.
}
public void actionPerformed(ActionEvent e) {
try {
String arg = e.getActionCommand();
if (arg.equals("Command 1")) handleCommand1();
else if (arg.equals("Command 2")) handleCommand2();
else if (arg.equals("Coimmand 3")) handleCommand3();
// etc.
} catch (Exception x) {
FrameworkUtils.error("Exception thrown: " + x);
}
}
private void handleCommand1() {
MyModel m = (MyModel)appWindow.getModel();
// update m
}
private void handleCommand2() { ... }
private void handleCommand3() { ... }
// etc.
}
Field Summary |
protected AppWindow |
appWindow
The AppWindow that this controller is attached to. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.awt.event.ActionListener |
actionPerformed |
appWindow
protected AppWindow appWindow
- The AppWindow that this controller is attached to.
From this we can get the model.
Controller
public Controller(AppWindow aw)
- Initializes appWindow.
- Parameters:
aw
- the appWindow that creates this controller.