Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyView extends JFrame implements ActionListener, ModelObserver {
- private MyController controller;
- public MyView(MyController controller) {
- super("My View");
- this.controller = controller;
- setSize(400, 60);
- setResizable(false);
- JButton button1 = new JButton("START");
- button1.addActionListener(this);
- JButton button2 = new JButton("STOP");
- button2.addActionListener(this);
- JPanel panel = new JPanel();
- panel.add(button1);
- panel.add(button2);
- setLayout(new BorderLayout());
- add(panel,BorderLayout.NORTH);
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent ev) {
- System.exit(-1);
- }
- });
- }
- public void actionPerformed(ActionEvent ev) {
- try {
- controller.processEvent(ev.getActionCommand());
- } catch (Exception ex) {
- }
- }
- @Override
- public void modelUpdated(MyModel model) {
- System.out.println("Model updated!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement