Advertisement
Guest User

gui

a guest
Mar 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class MyView extends JFrame implements ActionListener, ModelObserver {
  2.  
  3. private MyController controller;
  4.  
  5. public MyView(MyController controller) {
  6. super("My View");
  7.  
  8. this.controller = controller;
  9.  
  10. setSize(400, 60);
  11. setResizable(false);
  12.  
  13. JButton button1 = new JButton("START");
  14. button1.addActionListener(this);
  15.  
  16. JButton button2 = new JButton("STOP");
  17. button2.addActionListener(this);
  18.  
  19. JPanel panel = new JPanel();
  20. panel.add(button1);
  21. panel.add(button2);
  22.  
  23. setLayout(new BorderLayout());
  24. add(panel,BorderLayout.NORTH);
  25.  
  26. addWindowListener(new WindowAdapter() {
  27. public void windowClosing(WindowEvent ev) {
  28. System.exit(-1);
  29. }
  30. });
  31. }
  32.  
  33. public void actionPerformed(ActionEvent ev) {
  34. try {
  35. controller.processEvent(ev.getActionCommand());
  36. } catch (Exception ex) {
  37. }
  38. }
  39.  
  40. @Override
  41. public void modelUpdated(MyModel model) {
  42. System.out.println("Model updated!");
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement