Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. public class MVCOutline {
  2.  
  3. public static void main(String[] args) {
  4. EventQueue.invokeLater(new Runnable() {
  5. //@Override
  6. public void run() {
  7. new MVCOutline().create();
  8. }
  9. });
  10. }
  11.  
  12. private void create() {
  13. JFrame f = new JFrame("MVC Outline");
  14. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  15. f.add(new MainPanel());
  16. f.pack();
  17. f.setLocationRelativeTo(null);
  18. f.setVisible(true);
  19. }
  20. }
  21.  
  22. class MainPanel extends JPanel {
  23.  
  24. public MainPanel() {
  25. super(new BorderLayout());
  26. Model model = new Model();
  27. View view = new View(model);
  28. Control control = new Control(model, view);
  29. this.add(view, BorderLayout.CENTER);
  30. this.add(control, BorderLayout.WEST);
  31. }
  32. }
  33.  
  34. class Control extends JPanel implements ... {
  35.  
  36. private Model model;
  37. private View view;
  38.  
  39. public Control(Model model, View view) {
  40. this.model = model;
  41. this.view = view;
  42. }
  43. }
  44.  
  45. class View extends JPanel implements Observer {
  46.  
  47. private Model model;
  48.  
  49. public View(Model model) {
  50. this.model = model;
  51. model.addObserver(this);
  52. }
  53.  
  54. public void update(Observable o, Object arg) {
  55. // update GUI based on model
  56. }
  57. }
  58.  
  59. class Model extends Observable {
  60.  
  61. public void next() {
  62. this.notifyObservers(...);
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement