Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: schauder/architectureExample
base: a0e4cceaea
...
head fork: schauder/architectureExample
compare: 4151c44357
  • 4 commits
  • 18 files changed
  • 0 commit comments
  • 1 contributor
Showing with 272 additions and 129 deletions.
  1. +7 −1 src/de/schauderhaft/architecture/example/ConsoleStuff.java
  2. +0 −25 src/de/schauderhaft/architecture/example/CrosswordController.java
  3. +0 −20 src/de/schauderhaft/architecture/example/GuiStarter.java
  4. +0 −51 src/de/schauderhaft/architecture/example/InputView.java
  5. +0 −31 src/de/schauderhaft/architecture/example/ScoreBoard.java
  6. +10 −0 src/de/schauderhaft/architecture/example/swing/jens/GuiFactory.java
  7. +30 −0 src/de/schauderhaft/architecture/example/swing/jens/GuiStarter.java
  8. +23 −0 src/de/schauderhaft/architecture/example/swing/jens/ScoreBoardBuilder.java
  9. +46 −0 src/de/schauderhaft/architecture/example/swing/jens/SwingGuiFactory.java
  10. +7 −0 src/de/schauderhaft/architecture/example/swing/jens/ValueApi.java
  11. +10 −0 src/de/schauderhaft/architecture/example/swing/jens/ValueModel.java
  12. +27 −0 src/de/schauderhaft/architecture/example/swing/thomas/CrosswordController.java
  13. +22 −0 src/de/schauderhaft/architecture/example/swing/thomas/GuiStarter.java
  14. +52 −0 src/de/schauderhaft/architecture/example/swing/thomas/InputView.java
  15. +31 −0 src/de/schauderhaft/architecture/example/swing/thomas/ScoreBoard.java
  16. +3 −1 src/de/schauderhaft/architecture/example/{ → swing/thomas}/WordInputActionListener.java
  17. +2 −0  tst/de/schauderhaft/architecture/example/InputViewTest.java
  18. +2 −0  tst/de/schauderhaft/architecture/example/ScoreBoardTest.java
View
8 src/de/schauderhaft/architecture/example/ConsoleStuff.java
@@ -11,7 +11,13 @@ public static void main(String[] args) {
System.out.println("Spiel gestartet!");
System.out.print("Runde 1 Eingabe: ");
String input = makeInput();
- System.out.println(input + " bringt XXX Punkte! Gesamt: XXX");
+ System.out.println(input + " bringt " + machMalPunkte(input)
+ + " Punkte! Gesamt: XXX");
+ }
+
+ private static int machMalPunkte(String input) {
+ return 42;
+
}
private static String makeInput() {
View
25 src/de/schauderhaft/architecture/example/CrosswordController.java
@@ -1,25 +0,0 @@
-package de.schauderhaft.architecture.example;
-
-import javax.swing.JFrame;
-
-public class CrossWordController {
-
- private InputView view;
- private CrosswordGame crosswordGame;
-
- public CrossWordController(InputView view, CrosswordGame crosswordGame) {
- super();
- this.view = view;
- this.crosswordGame = crosswordGame;
- }
-
- public void start() {
-
- view.addActionForSubmit(new WordInputActionListener(view, crosswordGame));
-
- view.getInputView().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- view.getInputView().setVisible(true);
-
- }
-
-}
View
20 src/de/schauderhaft/architecture/example/GuiStarter.java
@@ -1,20 +0,0 @@
-package de.schauderhaft.architecture.example;
-
-import java.util.Arrays;
-import java.util.HashSet;
-
-public class GuiStarter {
-
- public static void main(String[] args) {
-
- InputView view = new InputView();
-
- CrosswordGame crosswordGame = new CrosswordGame(new HashSet<String>(
- Arrays.asList("Haus", "Maus", "Auto")));
-
- CrossWordController controller = new CrossWordController(view,
- crosswordGame);
- controller.start();
-
- }
-}
View
51 src/de/schauderhaft/architecture/example/InputView.java
@@ -1,51 +0,0 @@
-package de.schauderhaft.architecture.example;
-
-import java.awt.Dimension;
-import java.awt.FlowLayout;
-import java.awt.event.ActionListener;
-
-import javax.swing.JButton;
-import javax.swing.JFrame;
-import javax.swing.JTextField;
-
-public class InputView {
-
- JFrame frame = new JFrame("CrossWord");
-
- JTextField inputfield = new JTextField();
- JButton submit = new JButton("submit");
- ScoreBoard score = new ScoreBoard();
-
- public InputView() {
- inputfield.setPreferredSize(new Dimension(80, 20));
- frame.getContentPane().setLayout(new FlowLayout());
- frame.getContentPane().add(inputfield);
- frame.getContentPane().add(submit);
- frame.getContentPane().add(score.getScorePanel());
- frame.pack();
- }
-
- public JFrame getInputView() {
- return frame;
- }
-
- public void addActionForSubmit(ActionListener action) {
- submit.addActionListener(action);
- }
-
- /**
- * Access to inputfield
- *
- * @return
- */
- public String getInput() {
- return inputfield.getText();
-
- }
-
- public void newScore(int points) {
- score.newScore(points);
-
- }
-
-}
View
31 src/de/schauderhaft/architecture/example/ScoreBoard.java
@@ -1,31 +0,0 @@
-package de.schauderhaft.architecture.example;
-
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-
-public class ScoreBoard {
-
- JPanel container = new JPanel();
- JLabel text = new JLabel("Points:");
- JLabel points = new JLabel("0");
-
- public ScoreBoard() {
- container.add(text);
- container.add(points);
-
- }
-
- public JPanel getScorePanel() {
- return container;
- }
-
- /**
- * Add new value to label.
- *
- * @param newScore
- */
- public void newScore(int newScore) {
- points.setText(Integer.valueOf(newScore).toString());
- }
-
-}
View
10 src/de/schauderhaft/architecture/example/swing/jens/GuiFactory.java
@@ -0,0 +1,10 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+import de.schauderhaft.architecture.example.CrosswordGame;
+
+public interface GuiFactory {
+
+ /** create and starts an UI properly bound to the game */
+ void create(CrosswordGame game);
+
+}
View
30 src/de/schauderhaft/architecture/example/swing/jens/GuiStarter.java
@@ -0,0 +1,30 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import javax.swing.SwingUtilities;
+
+import de.schauderhaft.architecture.example.CrosswordGame;
+
+public class GuiStarter {
+
+ public static void main(String[] args) throws Exception {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ new GuiStarter().go();
+ }
+ });
+ }
+
+ private void go() {
+ GuiFactory factory = new SwingGuiFactory();
+ factory.create(new CrosswordGame(new HashSet<String>(Arrays.asList(
+ "Auto", "Maus", "Haus"))));
+ factory.create(new CrosswordGame(new HashSet<String>(Arrays.asList(
+ "Auto", "Maus", "Haus"))));
+ factory.create(new CrosswordGame(new HashSet<String>(Arrays.asList(
+ "Auto", "Maus", "Haus"))));
+ }
+}
View
23 src/de/schauderhaft/architecture/example/swing/jens/ScoreBoardBuilder.java
@@ -0,0 +1,23 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+
+public class ScoreBoardBuilder {
+
+ private final JLabel textbox = new JLabel("Points:");
+
+ public ValueApi getApi() {
+ return new ValueApi() {
+ @Override
+ public void setValue(int submit) {
+ textbox.setText("Points: " + submit);
+ }
+ };
+ }
+
+ public JComponent getComponent() {
+ return textbox;
+ }
+
+}
View
46 src/de/schauderhaft/architecture/example/swing/jens/SwingGuiFactory.java
@@ -0,0 +1,46 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+import static javax.swing.JFrame.EXIT_ON_CLOSE;
+
+import java.awt.Container;
+import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+
+import de.schauderhaft.architecture.example.CrosswordGame;
+
+public class SwingGuiFactory implements GuiFactory {
+
+ @Override
+ public void create(CrosswordGame game) {
+ JFrame main = new JFrame("Crossword Game");
+ Container contentPane = main.getContentPane();
+ addComponents(contentPane, game);
+ main.pack();
+ main.setDefaultCloseOperation(EXIT_ON_CLOSE);
+ main.setVisible(true);
+ }
+
+ private void addComponents(Container contentPane, final CrosswordGame game) {
+ final JTextField textbox = new JTextField(20);
+ JButton submit = new JButton("Submit");
+ final ScoreBoardBuilder scoreBoardBuilder = new ScoreBoardBuilder();
+
+ submit.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent action) {
+ scoreBoardBuilder.getApi().setValue(
+ game.submit(textbox.getText()));
+ }
+ });
+
+ contentPane.add(textbox);
+ contentPane.setLayout(new FlowLayout());
+ contentPane.add(submit);
+ contentPane.add(scoreBoardBuilder.getComponent());
+ }
+}
View
7 src/de/schauderhaft/architecture/example/swing/jens/ValueApi.java
@@ -0,0 +1,7 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+public interface ValueApi {
+
+ void setValue(int submit);
+
+}
View
10 src/de/schauderhaft/architecture/example/swing/jens/ValueModel.java
@@ -0,0 +1,10 @@
+package de.schauderhaft.architecture.example.swing.jens;
+
+public class ValueModel {
+
+ public void setValue(int submit) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
View
27 src/de/schauderhaft/architecture/example/swing/thomas/CrosswordController.java
@@ -0,0 +1,27 @@
+package de.schauderhaft.architecture.example.swing.thomas;
+
+import javax.swing.JFrame;
+
+import de.schauderhaft.architecture.example.CrosswordGame;
+
+public class CrosswordController {
+
+ private final InputView view;
+ private final CrosswordGame crosswordGame;
+
+ public CrosswordController(InputView view, CrosswordGame crosswordGame) {
+ super();
+ this.view = view;
+ this.crosswordGame = crosswordGame;
+ }
+
+ public void start() {
+
+ view.addActionForSubmit(new WordInputActionListener(view, crosswordGame));
+
+ view.getInputView().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ view.getInputView().setVisible(true);
+
+ }
+
+}
View
22 src/de/schauderhaft/architecture/example/swing/thomas/GuiStarter.java
@@ -0,0 +1,22 @@
+package de.schauderhaft.architecture.example.swing.thomas;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+import de.schauderhaft.architecture.example.CrosswordGame;
+
+public class GuiStarter {
+
+ public static void main(String[] args) {
+
+ InputView view = new InputView();
+
+ CrosswordGame crosswordGame = new CrosswordGame(new HashSet<String>(
+ Arrays.asList("Haus", "Maus", "Auto")));
+
+ CrosswordController controller = new CrosswordController(view,
+ crosswordGame);
+ controller.start();
+
+ }
+}
View
52 src/de/schauderhaft/architecture/example/swing/thomas/InputView.java
@@ -0,0 +1,52 @@
+package de.schauderhaft.architecture.example.swing.thomas;
+
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+
+public class InputView {
+
+ JFrame frame = new JFrame("CrossWord");
+
+ JTextField inputfield = new JTextField();
+ JButton submit = new JButton("submit");
+ ScoreBoard score = new ScoreBoard();
+
+ public InputView() {
+ inputfield.setPreferredSize(new Dimension(80, 20));
+ frame.getContentPane().setLayout(new FlowLayout());
+ frame.getContentPane().add(inputfield);
+ frame.getContentPane().add(submit);
+
+ frame.getContentPane().add(score.getScorePanel());
+ frame.pack();
+ }
+
+ public JFrame getInputView() {
+ return frame;
+ }
+
+ public void addActionForSubmit(ActionListener action) {
+ submit.addActionListener(action);
+ }
+
+ /**
+ * Access to inputfield
+ *
+ * @return
+ */
+ public String getInput() {
+ return inputfield.getText();
+
+ }
+
+ public void newScore(int points) {
+ score.newScore(points);
+
+ }
+
+}
View
31 src/de/schauderhaft/architecture/example/swing/thomas/ScoreBoard.java
@@ -0,0 +1,31 @@
+package de.schauderhaft.architecture.example.swing.thomas;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+public class ScoreBoard {
+
+ private final JPanel container = new JPanel();
+ private final JLabel text = new JLabel("Points:");
+ private final JLabel points = new JLabel("0");
+
+ public ScoreBoard() {
+ container.add(text);
+ container.add(points);
+
+ }
+
+ public JPanel getScorePanel() {
+ return container;
+ }
+
+ /**
+ * Add new value to label.
+ *
+ * @param newScore
+ */
+ public void newScore(int newScore) {
+ points.setText(Integer.valueOf(newScore).toString());
+ }
+
+}
View
4 ...ture/example/WordInputActionListener.java → ...swing/thomas/WordInputActionListener.java
@@ -1,8 +1,10 @@
-package de.schauderhaft.architecture.example;
+package de.schauderhaft.architecture.example.swing.thomas;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import de.schauderhaft.architecture.example.CrosswordGame;
+
public class WordInputActionListener implements ActionListener {
InputView view;
View
2  tst/de/schauderhaft/architecture/example/InputViewTest.java
@@ -10,6 +10,8 @@
import org.junit.Test;
+import de.schauderhaft.architecture.example.swing.thomas.InputView;
+
public class InputViewTest {
@Test
View
2  tst/de/schauderhaft/architecture/example/ScoreBoardTest.java
@@ -7,6 +7,8 @@
import org.junit.Test;
+import de.schauderhaft.architecture.example.swing.thomas.ScoreBoard;
+
public class ScoreBoardTest {
ScoreBoard underTest = new ScoreBoard();

No commit comments for this range

Something went wrong with that request. Please try again.