Skip to content

Commit

Permalink
mvp now with working actionlistener
Browse files Browse the repository at this point in the history
  • Loading branch information
brunofernandez1 committed Feb 2, 2018
1 parent 6c25d48 commit 558013c
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 97 deletions.
184 changes: 92 additions & 92 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/patterns/mvp/MVPTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static void main(String[] args) {
PersonView view = new PersonView();

PersonController controller = new PersonController(model, view);
view.addController(controller);
}

public static PersonModel createUser(){
Expand Down
9 changes: 6 additions & 3 deletions src/patterns/mvp/PersonController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package patterns.mvp;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

/**
* Created by Bruno on 01.02.2018.
*/
public class PersonController implements Observer {
public class PersonController implements ActionListener {
PersonModel model;
PersonView view;

Expand Down Expand Up @@ -35,8 +37,9 @@ public void updatePersonView(){
view.updateView();
}

@Override
public void update(Observable o, Object arg) {

@Override
public void actionPerformed(ActionEvent e) {
System.out.println("say yeah on controller");
}
}
12 changes: 10 additions & 2 deletions src/patterns/mvp/PersonView.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package patterns.mvp;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PersonView {
public class PersonView {

JFrame mainFrame;
JTextField textField;
PersonController controller;

public PersonView(){

Expand All @@ -17,7 +20,7 @@ public PersonView(){


JButton button = new JButton("this is a button");
//button.addActionListener(e -> );
button.addActionListener(e -> controller.actionPerformed(e));
JPanel rightPanel = new JPanel();
rightPanel.add(button);

Expand All @@ -36,4 +39,9 @@ public void updateView(){
textField.setText("Person was updated");
}

public void addController(PersonController controller){
this.controller = controller;
}


}

0 comments on commit 558013c

Please sign in to comment.