From bd2e2ff2fc75868751166da3903d83507511252a Mon Sep 17 00:00:00 2001 From: Nina Olear Date: Mon, 7 Jun 2021 04:01:45 +0200 Subject: [PATCH] refactor(comments): formatierung und zuweisungen --- src/Main.java | 9 +- src/controller/Category.java | 19 +- src/controller/Game.java | 21 +- src/controller/Options.java | 2 +- src/controller/Result.java | 6 +- src/controller/Screen.java | 17 +- src/controller/Switcher.java | 6 +- src/game/MissingQuestionsException.java | 2 +- src/game/MockQuestionStoreTest.java | 10 +- src/game/State.java | 3 + src/game/StateBuilder.java | 6 +- src/game/StateTest.java | 4 +- src/model/Category.java | 12 +- src/model/Question.java | 2 +- src/questions/QuestionDB.java | 341 ++++++++++-------------- src/questions/QuestionDBTest.java | 181 ++++++------- src/questions/QuestionParser.java | 57 ++-- src/questions/QuestionParserTest.java | 137 ++++++---- src/questions/QuestionStore.java | 10 +- src/tools/draw_uml/Main.java | 47 +--- src/tools/migration/Main.java | 80 +++--- src/ui/Router.java | 3 +- src/view/Category.java | 76 +++--- src/view/Edit.java | 173 ++++++------ src/view/Game.java | 139 +++++----- src/view/Options.java | 80 +++--- src/view/OptionsQuestionRow.java | 35 +-- src/view/Result.java | 89 ++++--- 28 files changed, 799 insertions(+), 768 deletions(-) diff --git a/src/Main.java b/src/Main.java index 4984eab..db70764 100644 --- a/src/Main.java +++ b/src/Main.java @@ -23,7 +23,7 @@ public class Main { public static void main(String[] args) { String filename = "questions.json"; - var q = new QuestionParser(); + QuestionParser q = new QuestionParser(); File file = new File(filename); try { InputStreamReader sr = new InputStreamReader(new FileInputStream(file)); @@ -43,8 +43,9 @@ public void run() { f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(1280, 720); f.setResizable(false); - // Entfernt Fensterrahmen, erst nachdem alle Exit-Buttons implementiert sind aktivieren - //f.setUndecorated(true); + // Entfernt Fensterrahmen, erst nachdem alle Exit-Buttons implementiert sind + // aktivieren + // f.setUndecorated(true); f.setLocationRelativeTo(null); f.setVisible(true); // NOTE: vielleicht muessen wir das laden vom screen mit dem starten @@ -64,7 +65,7 @@ public void run() { System.out.print("Failed to save questions, file: "); System.out.println(filename); System.exit(1); - } + } System.out.println("Saved questions!"); System.out.println("Bye!"); System.exit(0); diff --git a/src/controller/Category.java b/src/controller/Category.java index 3b49df3..37abc76 100644 --- a/src/controller/Category.java +++ b/src/controller/Category.java @@ -68,15 +68,16 @@ public void initCategoriesCheckBoxes(Share share) { if (c.toString() != "unknown" && c.toString() != "fun") { JCheckBox box = this.view.initAndAddNewCategoryCheckBox(category.toString()); box.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - if(e.getStateChange() == ItemEvent.SELECTED) { - selectedCategories.add(c); - } else { - selectedCategories.remove(c); - }; - updateStartButton(share); - } + @Override + public void itemStateChanged(ItemEvent e) { + if (e.getStateChange() == ItemEvent.SELECTED) { + selectedCategories.add(c); + } else { + selectedCategories.remove(c); + } + ; + updateStartButton(share); + } }); } } diff --git a/src/controller/Game.java b/src/controller/Game.java index beb9631..3371570 100644 --- a/src/controller/Game.java +++ b/src/controller/Game.java @@ -38,7 +38,7 @@ public Game(Switcher s, QuestionStore store) { public void init(Share share) { this.share = share; this.view = new view.Game(); - + final String key = "KEY_GAME_STATE"; if (!share.entryExists(key)) { // TODO: maybe we should allow a screen switch from @@ -55,9 +55,9 @@ public void init(Share share) { System.out.println("game: question is null"); System.exit(1); } - + this.initQuestion(share); - + this.initHomeButton(); this.initTitleLabel(); this.initExitButton(); @@ -70,24 +70,24 @@ public void init(Share share) { this.initLevelNo5Label(); this.initJokerButton(); } - + private void next() { this.question = this.state.next(); this.initQuestion(this.share); } - + private void initQuestion(Share share) { - + ActionListener right = new ActionListener() { public void actionPerformed(ActionEvent e) { share.put("KEY_GAME_WIN", new Object()); next(); if (question == null) { - switcher.next(Screen.SCREEN_RESULT); + switcher.next(Screen.SCREEN_RESULT); } } }; - + ActionListener wrong = new ActionListener() { public void actionPerformed(ActionEvent e) { share.put("KEY_GAME_QUESTION", question); @@ -95,9 +95,8 @@ public void actionPerformed(ActionEvent e) { } }; - ArrayList answers = this.question.getAnswers(); - + this.initQuestionLabel(this.question.getQuestion()); this.initCurrentCategoryLabel(this.question.getCategory().toString()); @@ -126,7 +125,7 @@ public void actionPerformed(ActionEvent e) { this.initAnswerNo3Button(answers.get(2), wrong); this.initAnswerNo4Button(answers.get(3), right); break; - default: + default: } } diff --git a/src/controller/Options.java b/src/controller/Options.java index 86fa741..70badcd 100644 --- a/src/controller/Options.java +++ b/src/controller/Options.java @@ -103,7 +103,7 @@ public void initQuestionRows(Share share) { for (Question q : this.store.getAllQuestions()) { OptionsQuestionRow oqr = new OptionsQuestionRow(); oqr.getQuestionLabel().setText(q.getQuestion()); - var c = q.getCategory(); + Category c = q.getCategory(); if (c == null) { c = new Category("unknown"); } diff --git a/src/controller/Result.java b/src/controller/Result.java index 9e66bb0..20cd684 100644 --- a/src/controller/Result.java +++ b/src/controller/Result.java @@ -29,7 +29,7 @@ public Result(Switcher s, QuestionStore store) { */ public void init(Share share) { this.view = new view.Result(); - + Question q = (Question) share.get("KEY_GAME_QUESTION"); boolean win = share.get("KEY_GAME_WIN") != null; this.initResultLabel(win); @@ -43,7 +43,7 @@ public void init(Share share) { this.initPlayerAnswerLeftLabel(); this.initPlayerAnswerRightLabel(); this.initCorrectAnswerLeftLabel(); - this.initCorrectAnswerRightLabel(q.getAnswers().get(q.getSolution())); + this.initCorrectAnswerRightLabel(q.getAnswers().get(q.getSolution())); } this.initHomeButton(); this.initExitButton(); @@ -57,7 +57,7 @@ public void initResultLabel(boolean win) { if (win) { this.view.getResultLabel().setText("Gewonnen!"); } - + } /** diff --git a/src/controller/Screen.java b/src/controller/Screen.java index e024a27..24e06a6 100644 --- a/src/controller/Screen.java +++ b/src/controller/Screen.java @@ -6,18 +6,11 @@ * */ public enum Screen { - SCREEN_START("start"), - SCREEN_CATEGORY("category"), - SCREEN_GAME("game"), - SCREEN_RESULT("result"), - SCREEN_OPTIONS("options"), - SCREEN_EDIT("edit"), - SCREEN_CREATE("create"), - SCREEN_EXIT("exit"), - ; - + SCREEN_START("start"), SCREEN_CATEGORY("category"), SCREEN_GAME("game"), SCREEN_RESULT("result"), + SCREEN_OPTIONS("options"), SCREEN_EDIT("edit"), SCREEN_CREATE("create"), SCREEN_EXIT("exit"),; + private final String text; - + /** * Konstruktor mit einem uebergabe Parameter * @@ -26,7 +19,7 @@ public enum Screen { Screen(final String text) { this.text = text; } - + /** * Gibt den screen namen als string zurueck. * diff --git a/src/controller/Switcher.java b/src/controller/Switcher.java index 1d3ba03..3e95a44 100644 --- a/src/controller/Switcher.java +++ b/src/controller/Switcher.java @@ -2,10 +2,8 @@ /** * - * Switcher.java - * Interface Klasse wird von Switchern implementiert. - * Ein next() call ueberfuehrt ein Objekt in den naechsten - * Zustand. + * Switcher.java Interface Klasse wird von Switchern implementiert. Ein next() + * call ueberfuehrt ein Objekt in den naechsten Zustand. * */ public interface Switcher { diff --git a/src/game/MissingQuestionsException.java b/src/game/MissingQuestionsException.java index 2bbf524..a9f998d 100644 --- a/src/game/MissingQuestionsException.java +++ b/src/game/MissingQuestionsException.java @@ -3,7 +3,7 @@ /** * Erstellung einer Exception, weil keine passende zur Verfuegung stand. */ -public class MissingQuestionsException extends Exception{ +public class MissingQuestionsException extends Exception { /** * */ diff --git a/src/game/MockQuestionStoreTest.java b/src/game/MockQuestionStoreTest.java index 2469c99..602b101 100644 --- a/src/game/MockQuestionStoreTest.java +++ b/src/game/MockQuestionStoreTest.java @@ -9,14 +9,14 @@ /** * Klasse wird benoetigt um eine Datenbank zu simulieren in spaeteren verlaeufen */ -public class MockQuestionStoreTest implements QuestionStore{ +public class MockQuestionStoreTest implements QuestionStore { private ArrayList db; - + public MockQuestionStoreTest(ArrayList db) { this.db = db; } - + @Override public ArrayList getAllQuestions() { // NOTE: unused @@ -49,7 +49,7 @@ public ArrayList getByCategory(Category c) { @Override public void create(Question q) { // NOTE: unused - + } @Override @@ -67,5 +67,5 @@ public ArrayList getCategories() { // TODO Auto-generated method stub return null; } - + } diff --git a/src/game/State.java b/src/game/State.java index 905f8d1..1d50b24 100644 --- a/src/game/State.java +++ b/src/game/State.java @@ -15,6 +15,7 @@ public class State { /** * Konstruktor mit zwei uebergabe Parametern + * * @param questions * @param levelfk */ @@ -28,6 +29,7 @@ public State(ArrayList questions, int levelfk) { /** * Wenn eine Question beantwortet wurde, dann gehe zur naechsten + * * @return q */ public Question next() { @@ -41,6 +43,7 @@ public Question next() { /** * Methode sagt aus in welchem Level man momentan ist + * * @return */ public int getLevel() { diff --git a/src/game/StateBuilder.java b/src/game/StateBuilder.java index b7c7057..cc8eb0b 100644 --- a/src/game/StateBuilder.java +++ b/src/game/StateBuilder.java @@ -108,11 +108,11 @@ private ArrayList limitQuestions(ArrayList input, int levelf counter++; result.add(input.get(i)); } - - if (result.size() < (levelMax-customLevel)*levelfk) { + + if (result.size() < (levelMax - customLevel) * levelfk) { throw new MissingQuestionsException(); } - + return result; } } diff --git a/src/game/StateTest.java b/src/game/StateTest.java index 65d4c7f..04ad73e 100644 --- a/src/game/StateTest.java +++ b/src/game/StateTest.java @@ -38,7 +38,7 @@ void tearDown() throws Exception { final void testNext() { State s = new State(new ArrayList(), 0); assertNull(s.next()); - + ArrayList questions = new ArrayList(); Category category = new Category("Test Kategory"); Question q1 = new Question(1, "wer", 2, null, 0, category); @@ -65,7 +65,7 @@ final void testGetLevel() { questions.add(q4); State s = new State(questions, 2); assertEquals(1, s.getLevel()); - + s.next(); s.next(); assertEquals(2, s.getLevel()); diff --git a/src/model/Category.java b/src/model/Category.java index 4c4c707..b397ad4 100644 --- a/src/model/Category.java +++ b/src/model/Category.java @@ -1,20 +1,20 @@ package model; /** - * Enum "Category" fuer die verschiedenen Kategorien - * welche wir fuer die Fragen benutzen wollen + * Enum "Category" fuer die verschiedenen Kategorien welche wir fuer die Fragen + * benutzen wollen * */ public class Category { - + private final String text; - + public Category(final String text) { - + this.text = text; } - + public String toString() { return this.text; } diff --git a/src/model/Question.java b/src/model/Question.java index 6178f90..f08b457 100644 --- a/src/model/Question.java +++ b/src/model/Question.java @@ -35,7 +35,7 @@ public int getID() { return id; } - public void setID(int id) { + public void setID(int id) { this.id = id; } diff --git a/src/questions/QuestionDB.java b/src/questions/QuestionDB.java index 0ff2a17..bdcf93f 100644 --- a/src/questions/QuestionDB.java +++ b/src/questions/QuestionDB.java @@ -3,7 +3,6 @@ import model.Question; import model.Category; - import java.sql.*; import java.util.ArrayList; @@ -12,10 +11,9 @@ public class QuestionDB implements QuestionStore { private Connection connection = null; private PreparedStatement preparedStatement = null; private ResultSet resultSet = null; - public QuestionDB() { - } + } public QuestionDB(Connection connection) { @@ -29,47 +27,38 @@ public Connection getConnection() { private void setConnection(Connection connection) { this.connection = connection; } - + @Override public Question getByID(int id) { - + try { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" - + " LEFT JOIN categories ON questions.category_id = categories.id" - + " WHERE questions.id = ?"; - + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.id = ?"; + preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, id); resultSet = preparedStatement.executeQuery(); - + while (resultSet.next()) { - - // Prepare answers - ArrayList answers = new ArrayList(); + + // Prepare answers + ArrayList answers = new ArrayList(); answers.add(resultSet.getString("answers.a")); answers.add(resultSet.getString("answers.b")); answers.add(resultSet.getString("answers.c")); answers.add(resultSet.getString("answers.d")); - - // Prepare category + + // Prepare category Category category = new Category(resultSet.getString("categories.name")); - // Create object - Question question = new Question( - resultSet.getInt("id"), - resultSet.getString("question"), - resultSet.getInt("difficulty"), - answers, - resultSet.getInt("solution"), - category - ); + // Create object + Question question = new Question(resultSet.getInt("id"), resultSet.getString("question"), + resultSet.getInt("difficulty"), answers, resultSet.getInt("solution"), category); return question; } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -80,43 +69,35 @@ public Question getByID(int id) { public ArrayList getByDifficulty(int difficulty) { ArrayList questions = new ArrayList(); - + try { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.difficulty = ?"; - + preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, difficulty); resultSet = preparedStatement.executeQuery(); - - // Prepare answers - ArrayList answers = new ArrayList(); + + // Prepare answers + ArrayList answers = new ArrayList(); answers.add(resultSet.getString("answers.a")); answers.add(resultSet.getString("answers.b")); answers.add(resultSet.getString("answers.c")); answers.add(resultSet.getString("answers.d")); - - // Prepare category + + // Prepare category Category category = new Category(resultSet.getString("categories.name")); while (resultSet.next()) { - Question question = new Question( - resultSet.getInt("id"), - resultSet.getString("question"), - resultSet.getInt("difficulty"), - answers, - resultSet.getInt("solution"), - category - ); + Question question = new Question(resultSet.getInt("id"), resultSet.getString("question"), + resultSet.getInt("difficulty"), answers, resultSet.getInt("solution"), category); questions.add((Question) question); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -127,44 +108,36 @@ public ArrayList getByDifficulty(int difficulty) { public ArrayList getByCategory(Category c) { ArrayList questions = new ArrayList(); - + try { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.category_id = ?"; - + preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, this.getCategoryIdByName(c)); resultSet = preparedStatement.executeQuery(); - - // Prepare answers - ArrayList answers = new ArrayList(); + + // Prepare answers + ArrayList answers = new ArrayList(); answers.add(resultSet.getString("answers.a")); answers.add(resultSet.getString("answers.b")); answers.add(resultSet.getString("answers.c")); answers.add(resultSet.getString("answers.d")); - - // Prepare category + + // Prepare category Category category = c; while (resultSet.next()) { - Question question = new Question( - resultSet.getInt("id"), - resultSet.getString("question"), - resultSet.getInt("difficulty"), - answers, - resultSet.getInt("solution"), - category - ); + Question question = new Question(resultSet.getInt("id"), resultSet.getString("question"), + resultSet.getInt("difficulty"), answers, resultSet.getInt("solution"), category); questions.add((Question) question); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -175,95 +148,85 @@ public ArrayList getByCategory(Category c) { public ArrayList getAllQuestions() { ArrayList questions = new ArrayList(); - + try { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + " LEFT JOIN categories ON questions.category_id = categories.id"; - + preparedStatement = connection.prepareStatement(query); resultSet = preparedStatement.executeQuery(); - - // Prepare answers - ArrayList answers = new ArrayList(); + + // Prepare answers + ArrayList answers = new ArrayList(); answers.add(resultSet.getString("answers.a")); answers.add(resultSet.getString("answers.b")); answers.add(resultSet.getString("answers.c")); answers.add(resultSet.getString("answers.d")); - - // Prepare category + + // Prepare category Category category = new Category(resultSet.getString("categories.name")); - + while (resultSet.next()) { - Question question = new Question( - resultSet.getInt("id"), - resultSet.getString("question"), - resultSet.getInt("difficulty"), - answers, - resultSet.getInt("solution"), - category - ); + Question question = new Question(resultSet.getInt("id"), resultSet.getString("question"), + resultSet.getInt("difficulty"), answers, resultSet.getInt("solution"), category); questions.add((Question) question); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return questions; } - + private int getAnswerIdByAnswers(ArrayList a) { int id = 0; - - if (this.getConnection() != null) { - + + if (this.getConnection() != null) { + try { - + String query = "SELECT id FROM answers WHERE a = ? AND b = ? AND c = ? AND d = ? LIMIT 1"; - + preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, a.get(0)); preparedStatement.setString(2, a.get(1)); preparedStatement.setString(3, a.get(2)); preparedStatement.setString(4, a.get(3)); resultSet = preparedStatement.executeQuery(); - + while (resultSet.next()) { - + id = resultSet.getInt("id"); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } return id; } - + public int getCategoryIdByName(Category c) { - - int id = 0; - + + int id = 0; + try { - + String query = "SELECT id FROM categories WHERE name = ? LIMIT 1"; - + preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, c.toString()); resultSet = preparedStatement.executeQuery(); - + while (resultSet.next()) { id = resultSet.getInt("id"); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -272,22 +235,21 @@ public int getCategoryIdByName(Category c) { @Override public ArrayList getCategories() { - - ArrayList categories = new ArrayList(); - + + ArrayList categories = new ArrayList(); + try { - + String query = "SELECT * FROM categories"; - + preparedStatement = connection.prepareStatement(query); resultSet = preparedStatement.executeQuery(); - + while (resultSet.next()) { - + categories.add(new Category(resultSet.getString("name"))); } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -296,19 +258,19 @@ public ArrayList getCategories() { @Override public void create(Question q) { - - if (this.getConnection() != null) { - + + if (this.getConnection() != null) { + try { - - // Get answer reference ID + + // Get answer reference ID int answer_id = this.getAnswerIdByAnswers(q.getAnswers()); - - // Get category reference ID + + // Get category reference ID int category_id = this.getCategoryIdByName(q.getCategory()); - + String query = "SELECT * FROM questions WHERE question = ? AND difficulty = ? AND answer_id = ? AND solution = ? AND category_id = ? LIMIT 1"; - + preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, q.getQuestion()); preparedStatement.setInt(2, q.getDifficulty()); @@ -316,13 +278,13 @@ public void create(Question q) { preparedStatement.setInt(4, q.getSolution()); preparedStatement.setInt(5, category_id); resultSet = preparedStatement.executeQuery(); - - if (!resultSet.next()) { - + + if (!resultSet.next()) { + // Insert query query = "INSERT INTO questions (question, difficulty, answer_id, solution, category_id)" - + " values (?, ?, ?, ?, ?)"; - + + " values (?, ?, ?, ?, ?)"; + preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, q.getQuestion()); preparedStatement.setInt(2, q.getDifficulty()); @@ -330,46 +292,40 @@ public void create(Question q) { preparedStatement.setInt(4, q.getSolution()); preparedStatement.setInt(5, category_id); preparedStatement.execute(); - + resultSet = preparedStatement.getGeneratedKeys(); int insertedId = 0; - + if (resultSet.next()) { - + insertedId = resultSet.getInt(1); q.setID(insertedId); - } - + } + } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } - + @Override public void update(Question q) { - - if (this.getConnection() != null) { + + if (this.getConnection() != null) { try { - - // Get answer reference ID + + // Get answer reference ID int answer_id = this.getAnswerIdByAnswers(q.getAnswers()); - - // Get category reference ID + + // Get category reference ID int category_id = this.getCategoryIdByName(q.getCategory()); - - String query = "UPDATE questions SET " - + "question = ?, " - + "difficulty = ?, " - + "answer_id = ?, " - + "solution = ?, " - + "category_id = ? " - + "WHERE id = ?"; - + + String query = "UPDATE questions SET " + "question = ?, " + "difficulty = ?, " + "answer_id = ?, " + + "solution = ?, " + "category_id = ? " + "WHERE id = ?"; + preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, q.getQuestion()); preparedStatement.setInt(2, q.getDifficulty()); @@ -378,8 +334,7 @@ public void update(Question q) { preparedStatement.setInt(5, category_id); preparedStatement.setInt(5, q.getID()); preparedStatement.execute(); - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -388,30 +343,29 @@ public void update(Question q) { @Override public void delete(int id) { - - if (this.getConnection() != null) { + + if (this.getConnection() != null) { try { - + String query = "DELETE FROM questions WHERE id = ?"; - + PreparedStatement preparedStmt = connection.prepareStatement(query); preparedStmt.setInt(1, id); preparedStmt.execute(); - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } - + public int saveAnswers(ArrayList a) { - - if (this.getConnection() != null) { - - try { - + + if (this.getConnection() != null) { + + try { + String query = "SELECT * FROM answers WHERE a = ? AND b = ? AND c = ? AND d = ?"; preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, a.get(0)); @@ -419,65 +373,62 @@ public int saveAnswers(ArrayList a) { preparedStatement.setString(3, a.get(2)); preparedStatement.setString(4, a.get(3)); resultSet = preparedStatement.executeQuery(); - - if (!resultSet.next()) { - + + if (!resultSet.next()) { + // No records found query = "INSERT INTO answers (a, b, c, d) values (?, ?, ?, ?)"; - + preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, a.get(0)); preparedStatement.setString(2, a.get(1)); preparedStatement.setString(3, a.get(2)); preparedStatement.setString(4, a.get(3)); preparedStatement.execute(); - + resultSet = preparedStatement.getGeneratedKeys(); - + if (resultSet.next()) { - + return resultSet.getInt(1); } } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } } return 0; } - - + public int saveCategory(Category category) { - - if (this.getConnection() != null) { - - try { - + + if (this.getConnection() != null) { + + try { + String query = "SELECT * FROM categories WHERE name = ?"; preparedStatement = connection.prepareStatement(query); preparedStatement.setString(1, category.toString()); resultSet = preparedStatement.executeQuery(); - - if (!resultSet.next()) { - + + if (!resultSet.next()) { + // No records found query = "INSERT INTO categories (name) values (?)"; - + preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, category.toString()); preparedStatement.execute(); - + resultSet = preparedStatement.getGeneratedKeys(); - + if (resultSet.next()) { - + return resultSet.getInt(1); } } - } - catch (SQLException e) { + } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } diff --git a/src/questions/QuestionDBTest.java b/src/questions/QuestionDBTest.java index 6338c00..983209c 100644 --- a/src/questions/QuestionDBTest.java +++ b/src/questions/QuestionDBTest.java @@ -22,109 +22,106 @@ @ExtendWith(MockitoExtension.class) public class QuestionDBTest { - - @Mock Connection connectionMock; - @Mock PreparedStatement preparedStatementMock; - @Mock ResultSet resultSetMock; - + + @Mock + Connection connectionMock; + @Mock + PreparedStatement preparedStatementMock; + @Mock + ResultSet resultSetMock; + QuestionDB QuestionDBMock; - - static ArrayList answers = new ArrayList(); + + static ArrayList answers = new ArrayList(); static Category category1 = new Category("Test Category"); static Category category2 = new Category("Test Category 2"); - + @BeforeAll public static void setUpBeforeAll() throws SQLException { - // Create questions list for assertion + // Create questions list for assertion answers.add("Test 1"); answers.add("Test 2"); answers.add("Test 3"); answers.add("Test 4"); } - + @BeforeEach public void setUpBeforeEach() throws SQLException { assertNotNull(connectionMock); assertNotNull(preparedStatementMock); - - QuestionDBMock = new QuestionDB(connectionMock); + + QuestionDBMock = new QuestionDB(connectionMock); } - + @Test public void testGetByID() throws SQLException { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" - + " LEFT JOIN categories ON questions.category_id = categories.id" - + " WHERE questions.id = ?"; + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.id = ?"; - // ----- Prepare mockery - Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); + // ----- Prepare mockery + Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); Mockito.when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock); - Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(true); + Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(true); Mockito.when(resultSetMock.getString("answers.a")).thenReturn("Test 1"); Mockito.when(resultSetMock.getString("answers.b")).thenReturn("Test 2"); Mockito.when(resultSetMock.getString("answers.c")).thenReturn("Test 3"); Mockito.when(resultSetMock.getString("answers.d")).thenReturn("Test 4"); Mockito.when(resultSetMock.getString("categories.name")).thenReturn("Test Category"); - + Mockito.when(resultSetMock.getInt("id")).thenReturn(1); Mockito.when(resultSetMock.getString("question")).thenReturn("Test Frage"); Mockito.when(resultSetMock.getInt("difficulty")).thenReturn(2); Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); - - // ----- Run Tests - // Test 1: Null + + // ----- Run Tests + // Test 1: Null assertNull(QuestionDBMock.getByID(1)); - - // Test 2: Not null - Don't equals - Question question = new Question(2, "Test Frage", 2, answers, 3, category1); - + + // Test 2: Not null - Don't equals + Question question = new Question(2, "Test Frage", 2, answers, 3, category1); + assertNotNull(QuestionDBMock.getByID(1)); assertNotEquals(QuestionDBMock.getByID(1).getID(), question.getID()); - - // Test 2: Not null - Equals - question.setID(1); + + // Test 2: Not null - Equals + question.setID(1); assertNotNull(QuestionDBMock.getByID(1)); assertEquals(question.getID(), QuestionDBMock.getByID(1).getID()); } - + @Test public void testGetByDifficulty() throws SQLException { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" - + " LEFT JOIN categories ON questions.category_id = categories.id" - + " WHERE questions.difficulty = ?"; - - // ----- Prepare mockery - Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.difficulty = ?"; + + // ----- Prepare mockery + Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); Mockito.when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock); - + Mockito.when(resultSetMock.getString("answers.a")).thenReturn("Test 1"); Mockito.when(resultSetMock.getString("answers.b")).thenReturn("Test 2"); Mockito.when(resultSetMock.getString("answers.c")).thenReturn("Test 3"); Mockito.when(resultSetMock.getString("answers.d")).thenReturn("Test 4"); Mockito.when(resultSetMock.getString("categories.name")).thenReturn("Test Category"); - Mockito.when(resultSetMock.next()) - .thenReturn(false) - .thenReturn(true).thenReturn(true).thenReturn(false) - .thenReturn(true).thenReturn(true).thenReturn(false); + Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(true).thenReturn(true).thenReturn(false) + .thenReturn(true).thenReturn(true).thenReturn(false); Mockito.when(resultSetMock.getInt("id")).thenReturn(1).thenReturn(1).thenReturn(1).thenReturn(4); Mockito.when(resultSetMock.getString("question")).thenReturn("Test Frage"); Mockito.when(resultSetMock.getInt("difficulty")).thenReturn(2); - Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); - - // ----- Run Tests - // Test 1: Empty array + Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); + + // ----- Run Tests + // Test 1: Empty array assertEquals(new ArrayList(), QuestionDBMock.getByDifficulty(2)); - - // Test 2: Not empty - assertNotEquals(new ArrayList(), QuestionDBMock.getByDifficulty(2)); + + // Test 2: Not empty + assertNotEquals(new ArrayList(), QuestionDBMock.getByDifficulty(2)); ArrayList questions = new ArrayList(); questions.add(new Question(1, "Test Frage #1", 2, answers, 1, category1)); @@ -133,46 +130,38 @@ public void testGetByDifficulty() throws SQLException { assertEquals(questions.size(), arrayList.size()); assertEquals(questions.get(0).getID(), arrayList.get(0).getID()); assertNotEquals(questions.get(1).getID(), arrayList.get(1).getID()); - } - + } + @Test public void testGetByCategory() throws SQLException { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" - + " LEFT JOIN categories ON questions.category_id = categories.id" - + " WHERE questions.category_id = ?"; + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " LEFT JOIN categories ON questions.category_id = categories.id" + " WHERE questions.category_id = ?"; String query2 = "SELECT id FROM categories WHERE name = ? LIMIT 1"; - // ----- Prepare mockery + // ----- Prepare mockery Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); - Mockito.when(connectionMock.prepareStatement(query2)).thenReturn(preparedStatementMock); + Mockito.when(connectionMock.prepareStatement(query2)).thenReturn(preparedStatementMock); Mockito.when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock); - + Mockito.when(resultSetMock.getString("answers.a")).thenReturn("Test 1"); Mockito.when(resultSetMock.getString("answers.b")).thenReturn("Test 2"); Mockito.when(resultSetMock.getString("answers.c")).thenReturn("Test 3"); Mockito.when(resultSetMock.getString("answers.d")).thenReturn("Test 4"); - Mockito.when(resultSetMock.next()) - .thenReturn(false).thenReturn(false) - .thenReturn(true).thenReturn(false).thenReturn(true).thenReturn(false) - .thenReturn(true).thenReturn(false).thenReturn(true).thenReturn(true).thenReturn(false); - Mockito.when(resultSetMock.getInt("id")) - .thenReturn(1) - .thenReturn(1) - .thenReturn(1) - .thenReturn(1) - .thenReturn(4); + Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(false).thenReturn(true).thenReturn(false) + .thenReturn(true).thenReturn(false).thenReturn(true).thenReturn(false).thenReturn(true).thenReturn(true) + .thenReturn(false); + Mockito.when(resultSetMock.getInt("id")).thenReturn(1).thenReturn(1).thenReturn(1).thenReturn(1).thenReturn(4); Mockito.when(resultSetMock.getString("question")).thenReturn("Test Frage"); Mockito.when(resultSetMock.getInt("difficulty")).thenReturn(2); - Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); - - // ----- Run Tests - // Test 1: Empty array + Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); + + // ----- Run Tests + // Test 1: Empty array assertEquals(new ArrayList(), QuestionDBMock.getByCategory(category1)); - - // Test 2: Not empty + + // Test 2: Not empty assertNotEquals(new ArrayList(), QuestionDBMock.getByCategory(category1)); ArrayList questions = new ArrayList(); @@ -182,40 +171,40 @@ public void testGetByCategory() throws SQLException { assertEquals(questions.size(), arrayList.size()); assertEquals(questions.get(0).getID(), arrayList.get(0).getID()); assertNotEquals(questions.get(1).getID(), arrayList.get(1).getID()); - } - + } + @Test public void testGetAllQuestions() throws SQLException { - + String query = "SELECT questions.*, answers.a, answers.b, answers.c, answers.d, categories.name" - + " FROM questions" - + " LEFT JOIN answers ON questions.answer_id = answers.id" - + " LEFT JOIN categories ON questions.category_id = categories.id"; - - // ----- Prepare mockery - Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); + + " FROM questions" + " LEFT JOIN answers ON questions.answer_id = answers.id" + + " LEFT JOIN categories ON questions.category_id = categories.id"; + + // ----- Prepare mockery + Mockito.when(connectionMock.prepareStatement(query)).thenReturn(preparedStatementMock); Mockito.when(preparedStatementMock.executeQuery()).thenReturn(resultSetMock); Mockito.when(resultSetMock.getString("answers.a")).thenReturn("Test 1"); Mockito.when(resultSetMock.getString("answers.b")).thenReturn("Test 2"); Mockito.when(resultSetMock.getString("answers.c")).thenReturn("Test 3"); Mockito.when(resultSetMock.getString("answers.d")).thenReturn("Test 4"); Mockito.when(resultSetMock.getString("categories.name")).thenReturn("Test Category"); - Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false); + Mockito.when(resultSetMock.next()).thenReturn(false).thenReturn(true).thenReturn(true).thenReturn(true) + .thenReturn(false); Mockito.when(resultSetMock.getInt("id")).thenReturn(1); Mockito.when(resultSetMock.getString("question")).thenReturn("Test Frage"); Mockito.when(resultSetMock.getInt("difficulty")).thenReturn(2); Mockito.when(resultSetMock.getInt("solution")).thenReturn(3); - - // ----- Run Tests - // Test 1: Empty array + + // ----- Run Tests + // Test 1: Empty array assertEquals(new ArrayList(), QuestionDBMock.getAllQuestions()); - - // Test 2: Not null - Don't equals - // Id, Question, Difficulty, Answers, Solution, Category + + // Test 2: Not null - Don't equals + // Id, Question, Difficulty, Answers, Solution, Category ArrayList questions = new ArrayList(); questions.add(new Question(1, "Test Frage #1", 2, answers, 1, category1)); questions.add(new Question(2, "Test Frage #2", 3, answers, 2, category1)); questions.add(new Question(3, "Test Frage #3", 4, answers, 3, category2)); assertEquals(questions.size(), QuestionDBMock.getAllQuestions().size()); - } + } } \ No newline at end of file diff --git a/src/questions/QuestionParser.java b/src/questions/QuestionParser.java index 259e1b4..15d54d6 100644 --- a/src/questions/QuestionParser.java +++ b/src/questions/QuestionParser.java @@ -4,6 +4,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; @@ -15,23 +16,22 @@ import model.Question; import model.Category; - public class QuestionParser implements QuestionStore { private ArrayList questions; private int nextID; /** - * Standard Konstruktor - * hier wird die ArrayList initialisiert + * Standard Konstruktor hier wird die ArrayList initialisiert */ public QuestionParser() { this.questions = new ArrayList(); this.nextID = 0; } - + /** * Konstruktor mit Parameter zur Uebergabe beim initialisieren + * * @param q */ public QuestionParser(ArrayList q) { @@ -40,13 +40,13 @@ public QuestionParser(ArrayList q) { /** * Laedt die Fragen aus einem json File in das Array "questions" + * * @param sr */ public void load(InputStreamReader sr) { Gson gson = new Gson(); - String json = new BufferedReader(sr) - .lines().collect(Collectors.joining("\n")); - var t = TypeToken.getParameterized(ArrayList.class, Question.class).getType(); + String json = new BufferedReader(sr).lines().collect(Collectors.joining("\n")); + Type t = TypeToken.getParameterized(ArrayList.class, Question.class).getType(); this.questions = gson.fromJson(json, t); for (Question q : this.questions) { int current = q.getID(); @@ -55,9 +55,10 @@ public void load(InputStreamReader sr) { } } } - + /** * Speichert die neuen Fragen in die ArrayList von questions + * * @param w */ public void save(OutputStreamWriter w) { @@ -76,6 +77,7 @@ public ArrayList getAllQuestions() { /** * Gibt eine Frage zurueck mit Angabe einer ID + * * @param id */ @Override @@ -90,6 +92,7 @@ public Question getByID(int id) { /** * Gibt eine oder mehrere Fragen zurueck mit Angabe des Schwierigkeitsgrades + * * @param difficulty */ @Override @@ -108,6 +111,7 @@ public ArrayList getByDifficulty(int difficulty) { /** * Gibt Fragen zurueck mit Angabe der Kategorie + * * @param c */ @Override @@ -126,6 +130,7 @@ public ArrayList getByCategory(Category c) { /** * Erstellt eine neue Frage fuer das Quiz + * * @param q */ @Override @@ -141,6 +146,7 @@ public void create(Question q) { /** * Updated das Quiz mit den neuen Fragen + * * @param qu */ @Override @@ -162,6 +168,7 @@ public void update(Question qu) { /** * Loescht die Fragen mit der dazugehoerigen ID + * * @param id */ @Override @@ -172,22 +179,22 @@ public void delete(int id) { return; } } - } - + } + @Override - public ArrayList getCategories() { - HashMap categories = new HashMap(); - for (Question q : this.questions) { - if (q.getCategory() == null) { - categories.put("unknown", new Category("unknown")); - continue; - } - categories.put(q.getCategory().toString(), q.getCategory()); - } - ArrayList res = new ArrayList(); - for (Entry e : categories.entrySet()) { - res.add(e.getValue()); - } - return res; - } + public ArrayList getCategories() { + HashMap categories = new HashMap(); + for (Question q : this.questions) { + if (q.getCategory() == null) { + categories.put("unknown", new Category("unknown")); + continue; + } + categories.put(q.getCategory().toString(), q.getCategory()); + } + ArrayList res = new ArrayList(); + for (Entry e : categories.entrySet()) { + res.add(e.getValue()); + } + return res; + } } \ No newline at end of file diff --git a/src/questions/QuestionParserTest.java b/src/questions/QuestionParserTest.java index 0c530f6..89fdc99 100644 --- a/src/questions/QuestionParserTest.java +++ b/src/questions/QuestionParserTest.java @@ -20,47 +20,24 @@ import model.Question; import model.Category; - /** * Klasse zum Testen der verschiedenen Methoden */ class QuestionParserTest { String text; - + @BeforeEach void setUp() throws Exception { - this.text = "[\n" - + " {\n" - + " \"id\": 1,\n" - + " \"question\": \"wie alt\",\n" - + " \"difficulty\": 5,\n" - + " \"answers\": [\n" - + " \"a1\",\n" - + " \"a2\",\n" - + " \"a3\",\n" - + " \"a4\"\n" - + " ],\n" - + " \"solution\": 3,\n" - + " \"category\": {\"text\":\"TestKategory\"}\n" - + " },\n" - + " {\n" - + " \"id\": 2,\n" - + " \"question\": \"wie toll\",\n" - + " \"difficulty\": 3,\n" - + " \"answers\": [\n" - + " \"a1\",\n" - + " \"a2\",\n" - + " \"a3\",\n" - + " \"a4\"\n" - + " ],\n" - + " \"solution\": 3,\n" - + " \"category\": {\"text\":\"TestKategory\"}\n" - + " }\n" - + "]\n" - + ""; - } - + this.text = "[\n" + " {\n" + " \"id\": 1,\n" + " \"question\": \"wie alt\",\n" + + " \"difficulty\": 5,\n" + " \"answers\": [\n" + " \"a1\",\n" + " \"a2\",\n" + + " \"a3\",\n" + " \"a4\"\n" + " ],\n" + " \"solution\": 3,\n" + + " \"category\": {\"text\":\"TestKategory\"}\n" + " },\n" + " {\n" + " \"id\": 2,\n" + + " \"question\": \"wie toll\",\n" + " \"difficulty\": 3,\n" + " \"answers\": [\n" + + " \"a1\",\n" + " \"a2\",\n" + " \"a3\",\n" + " \"a4\"\n" + " ],\n" + + " \"solution\": 3,\n" + " \"category\": {\"text\":\"TestKategory\"}\n" + " }\n" + "]\n" + ""; + } + /** * Test method for * {@link questions.QuestionParser#load(java.io.InputStreamReader)}. @@ -77,23 +54,31 @@ final void testLoad() { } assertEquals(q.getAllQuestions().size(), 2); } - + /** * Test method for * {@link questions.QuestionParser#save(java.io.OutputStreamWriter)}. - * @throws + * + * @throws */ @SuppressWarnings("serial") @Test final void testSave() { ArrayList questions = new ArrayList(); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Category category = new Category("Test Kategory"); questions.add(new Question(1, "wie alt", 5, aw, 3, category)); questions.add(new Question(2, "wie toll", 3, aw, 3, category)); QuestionParser q = new QuestionParser(questions); - OutputStream buf = new ByteArrayOutputStream(); - OutputStreamWriter w = new OutputStreamWriter(buf); + OutputStream buf = new ByteArrayOutputStream(); + OutputStreamWriter w = new OutputStreamWriter(buf); q.save(w); try { w.flush(); @@ -102,7 +87,7 @@ final void testSave() { fail("could not flush data"); } // NOTE: remove all whitespaces and non-visible characters (e.g., tab, \n). - assertEquals(this.text.replaceAll("\\s+",""), buf.toString().replaceAll("\\s+","")); + assertEquals(this.text.replaceAll("\\s+", ""), buf.toString().replaceAll("\\s+", "")); } /** @@ -112,15 +97,22 @@ final void testSave() { @Test final void testGetAllQuestions() { ArrayList questions = new ArrayList(); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Category category = new Category("Test Kategory"); questions.add(new Question(1, "wie", 100, aw, 2, category)); questions.add(new Question(2, "wo", 100, aw, 2, category)); questions.add(new Question(3, "was", 100, aw, 2, category)); QuestionParser q = new QuestionParser(questions); ArrayList nq = q.getAllQuestions(); - - assertEquals(questions,nq); + + assertEquals(questions, nq); } /** @@ -130,34 +122,47 @@ final void testGetAllQuestions() { @Test final void testGetQuestionByID() { ArrayList questions = new ArrayList(); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Category category = new Category("Test Kategory"); Question question = new Question(2, "wo", 100, aw, 2, category); questions.add(new Question(1, "wie", 100, aw, 2, category)); questions.add(question); questions.add(new Question(3, "was", 100, aw, 2, category)); QuestionParser q = new QuestionParser(questions); - - assertEquals(question,q.getByID(question.getID())); + + assertEquals(question, q.getByID(question.getID())); } /** - * Test method for - * {@link questions.QuestionParser#getByDifficulty(int)}. + * Test method for {@link questions.QuestionParser#getByDifficulty(int)}. */ @SuppressWarnings("serial") @Test final void testGetQuestionsByDifficulty() { final int targetDifficulty = 200; ArrayList questions = new ArrayList(); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Category category = new Category("Test Kategory"); Question question = new Question(2, "wo", targetDifficulty, aw, 2, category); questions.add(new Question(1, "wie", 100, aw, 2, category)); questions.add(question); questions.add(new Question(3, "was", 100, aw, 2, category)); QuestionParser q = new QuestionParser(questions); - + Question queried = q.getByDifficulty(targetDifficulty).get(0); assertEquals(question.getID(), queried.getID()); assertEquals(question.getQuestion(), queried.getQuestion()); @@ -173,16 +178,23 @@ final void testGetQuestionsByDifficulty() { @SuppressWarnings("serial") @Test final void testGetQuestionsByCategory() { - + Category category = new Category("Test Kategory"); ArrayList questions = new ArrayList(); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Question question = new Question(1, "wo", 100, aw, 2, category); questions.add(new Question(1, "wo", 100, aw, 2, category)); questions.add(question); questions.add(new Question(3, "was", 100, aw, 2, category)); QuestionParser q = new QuestionParser(questions); - + Question queried = q.getByCategory(category).get(0); assertEquals(question.getID(), queried.getID()); assertEquals(question.getQuestion(), queried.getQuestion()); @@ -192,13 +204,19 @@ final void testGetQuestionsByCategory() { } /** - * Test method for - * {@link questions.QuestionParser#create(questions.Question)}. + * Test method for {@link questions.QuestionParser#create(questions.Question)}. */ @SuppressWarnings("serial") @Test final void testCreateQuestion() { - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; Category category = new Category("Test Kategory"); Question q1 = new Question(1, "wo", 100, aw, 2, category); Question q2 = new Question(2, "wer", 100, aw, 2, category); @@ -217,7 +235,14 @@ final void testDeleteQuestion() { final int targetID = 1; ArrayList questions = new ArrayList(); Category category = new Category("Test Kategory"); - ArrayList aw = new ArrayList() {{ add("a1"); add("a2"); add("a3"); add("a4"); }}; + ArrayList aw = new ArrayList() { + { + add("a1"); + add("a2"); + add("a3"); + add("a4"); + } + }; questions.add(new Question(targetID, "wie", 100, aw, 2, category)); questions.add(new Question(2, "was", 100, aw, 2, category)); QuestionParser q = new QuestionParser(questions); diff --git a/src/questions/QuestionStore.java b/src/questions/QuestionStore.java index 881e2c5..5cc5028 100644 --- a/src/questions/QuestionStore.java +++ b/src/questions/QuestionStore.java @@ -6,15 +6,23 @@ import model.Category; /** - * Interface welches benutzt wird fuer die Implementation von den Methoden aus QuestionParser + * Interface welches benutzt wird fuer die Implementation von den Methoden aus + * QuestionParser */ public interface QuestionStore { public ArrayList getAllQuestions(); + public Question getByID(int id); + public ArrayList getByDifficulty(int difficulty); + public ArrayList getByCategory(Category c); + public ArrayList getCategories(); + public void create(Question q); + public void update(Question q); + public void delete(int id); } diff --git a/src/tools/draw_uml/Main.java b/src/tools/draw_uml/Main.java index 08c2c94..b18ea5c 100644 --- a/src/tools/draw_uml/Main.java +++ b/src/tools/draw_uml/Main.java @@ -1,6 +1,5 @@ package tools.draw_uml; - import java.io.FileNotFoundException; import java.io.PrintWriter; @@ -12,41 +11,23 @@ public class Main { public static void main(String[] args) { - var builder = new ClassDiagramBuilder(); - var diagram = builder - .addClasse(ui.Router.class) - .addClasse(ui.Registry.class) - .addClasse(questions.QuestionParser.class) - .addClasse(questions.QuestionStore.class) - .addClasse(questions.QuestionDB.class) - .addClasse(model.Category.class) - .addClasse(model.Question.class) - .addClasse(game.MissingQuestionsException.class) - .addClasse(game.State.class) - .addClasse(game.StateBuilder.class) - .addClasse(controller.Controller.class) - .addClasse(controller.Category.class) - .addClasse(controller.Create.class) - .addClasse(controller.Edit.class) - .addClasse(controller.Game.class) - .addClasse(controller.Options.class) - .addClasse(controller.Result.class) - .addClasse(controller.Screen.class) - .addClasse(controller.Share.class) - .addClasse(controller.Start.class) - .addClasse(controller.Switcher.class) - .addClasse(view.Edit.class) - .addClasse(view.Category.class) - .addClasse(view.Game.class) - .addClasse(view.Options.class) - .addClasse(view.OptionsQuestionRow.class) - .addClasse(view.Result.class) - .addClasse(view.Start.class) + ClassDiagramBuilder builder = new ClassDiagramBuilder(); + String diagram = builder.addClasse(ui.Router.class).addClasse(ui.Registry.class) + .addClasse(questions.QuestionParser.class).addClasse(questions.QuestionStore.class) + .addClasse(questions.QuestionDB.class).addClasse(model.Category.class).addClasse(model.Question.class) + .addClasse(game.MissingQuestionsException.class).addClasse(game.State.class) + .addClasse(game.StateBuilder.class).addClasse(controller.Controller.class) + .addClasse(controller.Category.class).addClasse(controller.Create.class) + .addClasse(controller.Edit.class).addClasse(controller.Game.class).addClasse(controller.Options.class) + .addClasse(controller.Result.class).addClasse(controller.Screen.class).addClasse(controller.Share.class) + .addClasse(controller.Start.class).addClasse(controller.Switcher.class).addClasse(view.Edit.class) + .addClasse(view.Category.class).addClasse(view.Game.class).addClasse(view.Options.class) + .addClasse(view.OptionsQuestionRow.class).addClasse(view.Result.class).addClasse(view.Start.class) .build(); - + System.out.println("done!"); try (PrintWriter out = new PrintWriter("diagram.puml")) { - out.println(diagram); + out.println(diagram); } catch (FileNotFoundException e) { e.printStackTrace(); } diff --git a/src/tools/migration/Main.java b/src/tools/migration/Main.java index a5f1420..68e1525 100644 --- a/src/tools/migration/Main.java +++ b/src/tools/migration/Main.java @@ -23,64 +23,62 @@ public static void main(String[] args) { Connection connection = getDatabaseConnection(); String filename = "questions.json"; File file = new File(filename); - + try { - + InputStreamReader sr = new InputStreamReader(new FileInputStream(file)); - var q = new QuestionParser(); + QuestionParser q = new QuestionParser(); q.load(sr); - - ArrayList questions = q.getAllQuestions(); - Iterator iterator = questions.iterator(); - while (iterator.hasNext()) { - - Question nextQuestionObj = (Question) iterator.next(); - - // get json column values + + ArrayList questions = q.getAllQuestions(); + Iterator iterator = questions.iterator(); + while (iterator.hasNext()) { + + Question nextQuestionObj = (Question) iterator.next(); + + // get json column values Category category = nextQuestionObj.getCategory(); String categoryName = category.toString(); ArrayList answers = nextQuestionObj.getAnswers(); - + QuestionDB questionDB = new QuestionDB(connection); - - // save category in database - Category Category = new Category(categoryName); - - // Save category in database - questionDB.saveCategory(Category); - - // Save answers in database + + // save category in database + Category Category = new Category(categoryName); + + // Save category in database + questionDB.saveCategory(Category); + + // Save answers in database questionDB.saveAnswers(answers); - // Save question in database - questionDB.create(nextQuestionObj); - } + // Save question in database + questionDB.create(nextQuestionObj); + } System.out.println("Migration: All questions, answers and categories have been added successfully."); - } - catch (FileNotFoundException e) { - + } catch (FileNotFoundException e) { + System.out.printf("could not load: %s\n", filename); } } - + private static Connection getDatabaseConnection() { - + Connection connection = null; - - try { - - String url = "jdbc:mysql://localhost:3306/quiz"; - String username = "root"; - String password = ""; - - connection = DriverManager.getConnection(url, username, password); - } - catch (SQLException ex) { - - System.out .println("An error occurred while connecting MySQL databse"); + + try { + + String url = "jdbc:mysql://localhost:3306/quiz"; + String username = "root"; + String password = ""; + + connection = DriverManager.getConnection(url, username, password); + } catch (SQLException ex) { + + System.out.println("An error occurred while connecting MySQL databse"); ex.printStackTrace(); } - + return connection; } } diff --git a/src/ui/Router.java b/src/ui/Router.java index b67f666..3385dc5 100644 --- a/src/ui/Router.java +++ b/src/ui/Router.java @@ -7,6 +7,7 @@ import javax.swing.JFrame; import javax.swing.JPanel; +import controller.Controller; import controller.Screen; import controller.Share; import controller.Switcher; @@ -47,7 +48,7 @@ public void Run() { while (this.next != Screen.SCREEN_EXIT) { System.out.print("Load screen: "); System.out.println(this.next.toString()); - var current = this.registry.get(this.next); + Controller current = this.registry.get(this.next); current.init(this.share); JPanel panel = current.toJPanel(); panel.setBorder(BorderFactory.createLineBorder(Color.CYAN, 5)); diff --git a/src/view/Category.java b/src/view/Category.java index 267e241..85f9f7e 100644 --- a/src/view/Category.java +++ b/src/view/Category.java @@ -17,12 +17,11 @@ /** * - * Category ist ein view, welches JComponents - * haelt und anbietet. + * Category ist ein view, welches JComponents haelt und anbietet. */ public class Category { private JPanel content; - + private JLabel categoryLabel; private JPanel categoryPanel; private JPanel leftPanel; @@ -37,14 +36,14 @@ public class Category { private JPanel rightPanel; private JPanel centerPanel; private JButton startButton; - + private final Font ARIAL_PLAIN_20 = new Font("Arial", Font.PLAIN, 20); private final Font ARIAL_BOLD_35 = new Font("Arial", Font.BOLD, 35); private final Font ARIAL_BOLD_70 = new Font("Arial", Font.BOLD, 70); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); private final Color BACKGROUND_COLOR = new Color(77, 77, 77); - + /** * Konstrukor zum erzeugen eines Category views. */ @@ -53,7 +52,7 @@ public Category() { this.initComponents(); this.initLayout(); } - + /** * Initialisiert components. */ @@ -61,7 +60,7 @@ private void initComponents() { this.categoryLabel = new JLabel(); this.categoryLabel.setFont(ARIAL_BOLD_35); this.categoryLabel.setForeground(STANDARD_COLOR); - + this.categoryPanel = new JPanel(); this.categoryPanel.setOpaque(false); @@ -71,7 +70,7 @@ private void initComponents() { this.levelLabel = new JLabel(); this.levelLabel.setFont(ARIAL_BOLD_35); this.levelLabel.setForeground(STANDARD_COLOR); - + this.levelNo1Button = new JRadioButton(); this.levelNo1Button.setFont(ARIAL_PLAIN_20); this.levelNo1Button.setForeground(STANDARD_COLOR); @@ -84,7 +83,7 @@ private void initComponents() { this.levelNo2Button.setForeground(STANDARD_COLOR); this.levelNo2Button.setBackground(BACKGROUND_COLOR); this.levelNo2Button.setFocusable(false); - + this.levelNo3Button = new JRadioButton(); this.levelNo3Button.setFont(ARIAL_PLAIN_20); this.levelNo3Button.setForeground(STANDARD_COLOR); @@ -104,16 +103,16 @@ private void initComponents() { this.levelNo5Button.setFocusable(false); this.buttonGroup = new ButtonGroup(); - + this.levelPanel = new JPanel(); this.levelPanel.setOpaque(false); this.rightPanel = new JPanel(); this.rightPanel.setOpaque(false); - + this.centerPanel = new JPanel(); this.centerPanel.setOpaque(false); - + this.startButton = new JButton(); this.startButton.setFont(ARIAL_BOLD_70); this.startButton.setForeground(STANDARD_COLOR); @@ -122,23 +121,23 @@ private void initComponents() { this.startButton.setBorder(BorderFactory.createMatteBorder(5, 0, 0, 0, STANDARD_COLOR)); this.startButton.setFocusPainted(false); } - + /** * Initialisiert view layout. */ private void initLayout() { this.categoryPanel.setLayout(new BoxLayout(categoryPanel, BoxLayout.Y_AXIS)); this.categoryPanel.add(categoryLabel); - + this.leftPanel.setLayout(new GridBagLayout()); this.leftPanel.add(categoryPanel); - + this.buttonGroup.add(levelNo1Button); this.buttonGroup.add(levelNo2Button); this.buttonGroup.add(levelNo3Button); this.buttonGroup.add(levelNo4Button); this.buttonGroup.add(levelNo5Button); - + this.levelPanel.setLayout(new BoxLayout(levelPanel, BoxLayout.Y_AXIS)); this.levelPanel.add(levelLabel); this.levelPanel.add(levelNo1Button); @@ -146,19 +145,19 @@ private void initLayout() { this.levelPanel.add(levelNo3Button); this.levelPanel.add(levelNo4Button); this.levelPanel.add(levelNo5Button); - + this.rightPanel.setLayout(new GridBagLayout()); this.rightPanel.add(levelPanel); - + this.centerPanel.setLayout(new GridLayout(1, 2)); this.centerPanel.add(leftPanel); this.centerPanel.add(rightPanel); - + this.content.setLayout(new BorderLayout()); this.content.add(centerPanel, BorderLayout.CENTER); this.content.add(startButton, BorderLayout.SOUTH); } - + /** * Initialisiert und hinzufuegt die Category-CheckBox */ @@ -168,93 +167,104 @@ public JCheckBox initAndAddNewCategoryCheckBox(String categoryText) { categoryCheckBox.setForeground(STANDARD_COLOR); categoryCheckBox.setBackground(BACKGROUND_COLOR); categoryCheckBox.setFocusable(false); - + this.categoryPanel.add(categoryCheckBox); return categoryCheckBox; } - + /** * Gibt das Content-Panel zurueck + * * @return JPanel */ public JPanel getContent() { return this.content; } - + /** * Gibt das Category-Label zurueck + * * @return JLabel */ public JLabel getCategoryLabel() { return this.categoryLabel; } - + /** * Gibt das Category-Panel zurueck + * * @return JPanel */ public JPanel getCategoryPanel() { return this.categoryPanel; } - + /** * Gibt das Level-Label zurueck + * * @return JLabel */ public JLabel getLevelLabel() { return this.levelLabel; } - + /** * Gibt den LevelNo1-Button zurueck + * * @return JRadioButton */ public JRadioButton getLevelNo1Button() { return this.levelNo1Button; } - + /** * Gibt den LevelNo2-Button zurueck + * * @return JRadioButton */ public JRadioButton getLevelNo2Button() { return this.levelNo2Button; } - + /** * Gibt den LevelNo3-Button zurueck + * * @return JRadioButton */ public JRadioButton getLevelNo3Button() { return this.levelNo3Button; } - + /** * Gibt den LevelNo4-Button zurueck + * * @return JRadioButton */ public JRadioButton getLevelNo4Button() { return this.levelNo4Button; } - + /** * Gibt den LevelNo5-Button zurueck + * * @return JRadioButton */ public JRadioButton getLevelNo5Button() { return this.levelNo5Button; } - + /** * Gibt die ButtonGroup zurueck + * * @return ButtonGroup */ public ButtonGroup getButtonGroup() { return this.buttonGroup; } - + /** * Gibt den Start-Button zurueck + * * @return JButton */ public JButton getStartButton() { diff --git a/src/view/Edit.java b/src/view/Edit.java index 53c6b52..00ddd4e 100644 --- a/src/view/Edit.java +++ b/src/view/Edit.java @@ -17,12 +17,11 @@ /** * - * Edit ist ein view, welches JComponents - * haelt und anbietet. + * Edit ist ein view, welches JComponents haelt und anbietet. */ public class Edit { private JPanel content; - + private JLabel questionLabel; private JTextField questionTextField; private JPanel questionPanel; @@ -53,13 +52,13 @@ public class Edit { private JButton saveButton; private JButton cancelButton; private JPanel bottomPanel; - + private final Font ARIAL_BOLD_50 = new Font("Arial", Font.BOLD, 50); private final Font ARIAL_PLAIN_50 = new Font("Arial", Font.PLAIN, 50); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); private final Color BACKGROUND_COLOR = new Color(77, 77, 77); - + /** * Konstrukor zum erzeugen eines Edit views. */ @@ -68,7 +67,7 @@ public Edit() { this.initComponents(); this.initLayout(); } - + /** * Initialisiert components. */ @@ -76,24 +75,24 @@ private void initComponents() { this.questionLabel = new JLabel(); this.questionLabel.setFont(ARIAL_PLAIN_50); this.questionLabel.setForeground(STANDARD_COLOR); - + this.questionTextField = new JTextField(); this.questionTextField.setOpaque(false); - this.questionTextField.setPreferredSize(new Dimension(1072,50)); + this.questionTextField.setPreferredSize(new Dimension(1072, 50)); this.questionTextField.setFont(ARIAL_PLAIN_50); this.questionTextField.setForeground(STANDARD_COLOR); this.questionTextField.setBackground(TRANSPARENT_COLOR); this.questionTextField.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); - + this.questionPanel = new JPanel(); this.questionPanel.setOpaque(false); - + this.categoryLabel = new JLabel(); this.categoryLabel.setFont(ARIAL_PLAIN_50); this.categoryLabel.setForeground(STANDARD_COLOR); - + this.categoryComboBox = new JComboBox(); - this.categoryComboBox.setPreferredSize(new Dimension(350,50)); + this.categoryComboBox.setPreferredSize(new Dimension(350, 50)); this.categoryComboBox.setFont(ARIAL_PLAIN_50); this.categoryComboBox.setForeground(STANDARD_COLOR); this.categoryComboBox.setBackground(BACKGROUND_COLOR); @@ -103,102 +102,102 @@ private void initComponents() { this.categoryComboBox.getEditor().getEditorComponent().setForeground(STANDARD_COLOR); this.categoryComboBox.getEditor().getEditorComponent().setBackground(BACKGROUND_COLOR); this.categoryComboBox.getComponent(0).setBackground(STANDARD_COLOR); - + this.categoryPanel = new JPanel(); this.categoryPanel.setOpaque(false); - + this.levelLabel = new JLabel(); this.levelLabel.setFont(ARIAL_PLAIN_50); this.levelLabel.setForeground(STANDARD_COLOR); - + this.levelComboBox = new JComboBox(); - this.levelComboBox.setPreferredSize(new Dimension(100,50)); + this.levelComboBox.setPreferredSize(new Dimension(100, 50)); this.levelComboBox.setFont(ARIAL_PLAIN_50); this.levelComboBox.setForeground(STANDARD_COLOR); this.levelComboBox.setBackground(BACKGROUND_COLOR); this.levelComboBox.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); this.levelComboBox.getComponent(0).setBackground(STANDARD_COLOR); - + this.levelPanel = new JPanel(); this.levelPanel.setOpaque(false); - + this.categoryLevelPanel = new JPanel(); this.categoryLevelPanel.setOpaque(false); - + this.answerNo1Button = new JRadioButton(); this.answerNo1Button.setBackground(BACKGROUND_COLOR); - + this.answerNo1Label = new JLabel(); this.answerNo1Label.setFont(ARIAL_PLAIN_50); this.answerNo1Label.setForeground(STANDARD_COLOR); - + this.answerNo1TextField = new JTextField(); this.answerNo1TextField.setOpaque(false); - this.answerNo1TextField.setPreferredSize(new Dimension(900,50)); + this.answerNo1TextField.setPreferredSize(new Dimension(900, 50)); this.answerNo1TextField.setFont(ARIAL_PLAIN_50); this.answerNo1TextField.setForeground(STANDARD_COLOR); this.answerNo1TextField.setBackground(TRANSPARENT_COLOR); this.answerNo1TextField.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); - + this.answerNo1Panel = new JPanel(); this.answerNo1Panel.setOpaque(false); - + this.answerNo2Button = new JRadioButton(); this.answerNo2Button.setBackground(BACKGROUND_COLOR); - + this.answerNo2Label = new JLabel(); this.answerNo2Label.setFont(ARIAL_PLAIN_50); this.answerNo2Label.setForeground(STANDARD_COLOR); - + this.answerNo2TextField = new JTextField(); this.answerNo2TextField.setOpaque(false); - this.answerNo2TextField.setPreferredSize(new Dimension(900,50)); + this.answerNo2TextField.setPreferredSize(new Dimension(900, 50)); this.answerNo2TextField.setFont(ARIAL_PLAIN_50); this.answerNo2TextField.setForeground(STANDARD_COLOR); this.answerNo2TextField.setBackground(TRANSPARENT_COLOR); this.answerNo2TextField.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); - + this.answerNo2Panel = new JPanel(); this.answerNo2Panel.setOpaque(false); - + this.answerNo3Button = new JRadioButton(); this.answerNo3Button.setBackground(BACKGROUND_COLOR); - + this.answerNo3Label = new JLabel(); this.answerNo3Label.setFont(ARIAL_PLAIN_50); this.answerNo3Label.setForeground(STANDARD_COLOR); - + this.answerNo3TextField = new JTextField(); this.answerNo3TextField.setOpaque(false); - this.answerNo3TextField.setPreferredSize(new Dimension(900,50)); + this.answerNo3TextField.setPreferredSize(new Dimension(900, 50)); this.answerNo3TextField.setFont(ARIAL_PLAIN_50); this.answerNo3TextField.setForeground(STANDARD_COLOR); this.answerNo3TextField.setBackground(TRANSPARENT_COLOR); this.answerNo3TextField.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); - + this.answerNo3Panel = new JPanel(); this.answerNo3Panel.setOpaque(false); - + this.answerNo4Button = new JRadioButton(); this.answerNo4Button.setBackground(BACKGROUND_COLOR); - + this.answerNo4Label = new JLabel(); this.answerNo4Label.setFont(ARIAL_PLAIN_50); this.answerNo4Label.setForeground(STANDARD_COLOR); - + this.answerNo4TextField = new JTextField(); this.answerNo4TextField.setOpaque(false); - this.answerNo4TextField.setPreferredSize(new Dimension(900,50)); + this.answerNo4TextField.setPreferredSize(new Dimension(900, 50)); this.answerNo4TextField.setFont(ARIAL_PLAIN_50); this.answerNo4TextField.setForeground(STANDARD_COLOR); this.answerNo4TextField.setBackground(TRANSPARENT_COLOR); this.answerNo4TextField.setBorder(BorderFactory.createLineBorder(STANDARD_COLOR, 1)); - + this.answerNo4Panel = new JPanel(); this.answerNo4Panel.setOpaque(false); - + this.buttonGroup = new ButtonGroup(); - + this.saveButton = new JButton(); this.saveButton.setFont(ARIAL_BOLD_50); this.saveButton.setForeground(STANDARD_COLOR); @@ -206,7 +205,7 @@ private void initComponents() { this.saveButton.setContentAreaFilled(false); this.saveButton.setBorder(null); this.saveButton.setFocusPainted(false); - + this.cancelButton = new JButton(); this.cancelButton.setFont(ARIAL_BOLD_50); this.cancelButton.setForeground(STANDARD_COLOR); @@ -214,12 +213,12 @@ private void initComponents() { this.cancelButton.setContentAreaFilled(false); this.cancelButton.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 0, STANDARD_COLOR)); this.cancelButton.setFocusPainted(false); - + this.bottomPanel = new JPanel(); this.bottomPanel.setOpaque(false); this.bottomPanel.setBorder(BorderFactory.createMatteBorder(5, 0, 0, 0, STANDARD_COLOR)); } - + /** * Initialisiert view layout. */ @@ -227,48 +226,48 @@ public void initLayout() { this.questionPanel.setLayout(new FlowLayout(FlowLayout.LEADING)); this.questionPanel.add(questionLabel); this.questionPanel.add(questionTextField); - + this.categoryPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); this.categoryPanel.add(categoryLabel); this.categoryPanel.add(categoryComboBox); - + this.levelPanel.setLayout(new FlowLayout(FlowLayout.CENTER)); this.levelPanel.add(levelLabel); this.levelPanel.add(levelComboBox); - + this.categoryLevelPanel.setLayout(new GridLayout(1, 2)); this.categoryLevelPanel.add(categoryPanel); this.categoryLevelPanel.add(levelPanel); - + this.answerNo1Panel.setLayout(new FlowLayout(FlowLayout.LEADING)); this.answerNo1Panel.add(answerNo1Button); this.answerNo1Panel.add(answerNo1Label); this.answerNo1Panel.add(answerNo1TextField); - + this.answerNo2Panel.setLayout(new FlowLayout(FlowLayout.LEADING)); this.answerNo2Panel.add(answerNo2Button); this.answerNo2Panel.add(answerNo2Label); this.answerNo2Panel.add(answerNo2TextField); - + this.answerNo3Panel.setLayout(new FlowLayout(FlowLayout.LEADING)); this.answerNo3Panel.add(answerNo3Button); this.answerNo3Panel.add(answerNo3Label); this.answerNo3Panel.add(answerNo3TextField); - + this.answerNo4Panel.setLayout(new FlowLayout(FlowLayout.LEADING)); this.answerNo4Panel.add(answerNo4Button); this.answerNo4Panel.add(answerNo4Label); this.answerNo4Panel.add(answerNo4TextField); - + this.buttonGroup.add(answerNo1Button); this.buttonGroup.add(answerNo2Button); this.buttonGroup.add(answerNo3Button); this.buttonGroup.add(answerNo4Button); - + this.bottomPanel.setLayout(new GridLayout(1, 2)); this.bottomPanel.add(saveButton); this.bottomPanel.add(cancelButton); - + this.content.setLayout(new GridLayout(7, 1)); this.content.add(questionPanel); this.content.add(categoryLevelPanel); @@ -278,177 +277,199 @@ public void initLayout() { this.content.add(answerNo4Panel); this.content.add(bottomPanel); } - + /** * Gibt das Content-Panel zurueck + * * @return JPanel */ public JPanel getContent() { return this.content; } - + /** * Gibt das Question-Label zurueck + * * @return JLabel */ public JLabel getQuestionLabel() { return this.questionLabel; } - + /** * Gibt das Question-TextField zurueck + * * @return JTextField */ public JTextField getQuestionTextField() { return this.questionTextField; } - + /** * Gibt das Category-Label zurueck + * * @return JLabel */ public JLabel getCategoryLabel() { return this.categoryLabel; } - + /** * Gibt das Category-ComboBox zurueck + * * @return JComboBox */ public JComboBox getCategoryComboBox() { return this.categoryComboBox; } - + /** * Gibt das Level-Label zurueck + * * @return JLabel */ public JLabel getLevelLabel() { return this.levelLabel; } - + /** * Gibt das Level-ComboBox zurueck + * * @return JComboBox */ public JComboBox getLevelComboBox() { return this.levelComboBox; } - + /** * Gibt den AnswerNo1-Button zurueck + * * @return JRadioButton */ public JRadioButton getAnswerNo1Button() { return this.answerNo1Button; } - + /** * Gibt das AnswerNo1-Label zurueck + * * @return JLabel */ public JLabel getAnswerNo1Label() { return this.answerNo1Label; } - + /** * Gibt das AnswerNo1-TextField zurueck + * * @return JTextField */ public JTextField getAnswerNo1TextField() { return this.answerNo1TextField; } - + /** * Gibt den AnswerNo2-Button zurueck + * * @return JRadioButton */ public JRadioButton getAnswerNo2Button() { return this.answerNo2Button; } - + /** * Gibt das AnswerNo2-Label zurueck + * * @return JLabel */ public JLabel getAnswerNo2Label() { return this.answerNo2Label; } - + /** * Gibt das AnswerNo2-TextField zurueck + * * @return JTextField */ public JTextField getAnswerNo2TextField() { return this.answerNo2TextField; } - + /** * Gibt den AnswerNo3-Button zurueck + * * @return JRadioButton */ public JRadioButton getAnswerNo3Button() { return this.answerNo3Button; } - + /** * Gibt das AnswerNo3-Label zurueck + * * @return JLabel */ public JLabel getAnswerNo3Label() { return this.answerNo3Label; } - + /** * Gibt das AnswerNo3-TextField zurueck + * * @return JTextField */ public JTextField getAnswerNo3TextField() { return this.answerNo3TextField; } - + /** * Gibt den AnswerNo4-Button zurueck + * * @return JRadioButton */ public JRadioButton getAnswerNo4Button() { return this.answerNo4Button; } - + /** * Gibt das AnswerNo4-Label zurueck + * * @return JLabel */ public JLabel getAnswerNo4Label() { return this.answerNo4Label; } - + /** * Gibt das AnswerNo4-TextField zurueck + * * @return JTextField */ public JTextField getAnswerNo4TextField() { return this.answerNo4TextField; } - + /** * Gibt die ButtonGroup zurueck + * * @return ButtonGroup */ public ButtonGroup getButtonGroup() { return this.buttonGroup; } - + /** * Gibt den Save-Button zurueck + * * @return JButton */ public JButton getSaveButton() { return this.saveButton; } - + /** * Gibt den Cancel-Button zurueck + * * @return JButton */ public JButton getCancelButton() { diff --git a/src/view/Game.java b/src/view/Game.java index 7aeb6b5..99b23c3 100644 --- a/src/view/Game.java +++ b/src/view/Game.java @@ -13,13 +13,12 @@ /** * - * Game ist ein view, welches JComponents - * haelt und anbietet. + * Game ist ein view, welches JComponents haelt und anbietet. * */ public class Game { private JPanel content; - + private JButton homeButton; private JLabel titleLabel; private JButton exitButton; @@ -44,13 +43,13 @@ public class Game { private JButton jokerButton; private JPanel jokerPanel; private JPanel rightPanel; - + private final Font ARIAL_BOLD_70 = new Font("Arial", Font.BOLD, 70); private final Font ARIAL_PLAIN_50 = new Font("Arial", Font.PLAIN, 50); private final Font ARIAL_PLAIN_20 = new Font("Arial", Font.PLAIN, 20); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); - + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); + /** * Konstrukor zum erzeugen eines Game views. */ @@ -59,7 +58,7 @@ public Game() { this.initComponents(); this.initLayout(); } - + /** * Initialisiert components. */ @@ -71,13 +70,13 @@ private void initComponents() { this.homeButton.setContentAreaFilled(false); this.homeButton.setBorder(null); this.homeButton.setFocusPainted(false); - + this.titleLabel = new JLabel(); this.titleLabel.setHorizontalAlignment(SwingConstants.CENTER); this.titleLabel.setFont(ARIAL_BOLD_70); this.titleLabel.setForeground(STANDARD_COLOR); this.titleLabel.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 5, STANDARD_COLOR)); - + this.exitButton = new JButton(); this.exitButton.setFont(ARIAL_BOLD_70); this.exitButton.setForeground(Color.RED); @@ -85,16 +84,16 @@ private void initComponents() { this.exitButton.setContentAreaFilled(false); this.exitButton.setBorder(null); this.exitButton.setFocusPainted(false); - + this.topPanel = new JPanel(); this.topPanel.setOpaque(false); this.topPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, STANDARD_COLOR)); - + this.questionLabel = new JLabel(); this.questionLabel.setHorizontalAlignment(SwingConstants.CENTER); this.questionLabel.setFont(ARIAL_PLAIN_50); this.questionLabel.setForeground(STANDARD_COLOR); - + this.answerNo1Button = new JButton(); this.answerNo1Button.setFont(ARIAL_PLAIN_50); this.answerNo1Button.setForeground(STANDARD_COLOR); @@ -102,7 +101,7 @@ private void initComponents() { this.answerNo1Button.setContentAreaFilled(false); this.answerNo1Button.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 2, STANDARD_COLOR)); this.answerNo1Button.setFocusPainted(false); - + this.answerNo2Button = new JButton(); this.answerNo2Button.setFont(ARIAL_PLAIN_50); this.answerNo2Button.setForeground(STANDARD_COLOR); @@ -110,7 +109,7 @@ private void initComponents() { this.answerNo2Button.setContentAreaFilled(false); this.answerNo2Button.setBorder(BorderFactory.createMatteBorder(0, 3, 2, 0, STANDARD_COLOR)); this.answerNo2Button.setFocusPainted(false); - + this.answerNo3Button = new JButton(); this.answerNo3Button.setFont(ARIAL_PLAIN_50); this.answerNo3Button.setForeground(STANDARD_COLOR); @@ -118,7 +117,7 @@ private void initComponents() { this.answerNo3Button.setContentAreaFilled(false); this.answerNo3Button.setBorder(BorderFactory.createMatteBorder(3, 0, 0, 2, STANDARD_COLOR)); this.answerNo3Button.setFocusPainted(false); - + this.answerNo4Button = new JButton(); this.answerNo4Button.setFont(ARIAL_PLAIN_50); this.answerNo4Button.setForeground(STANDARD_COLOR); @@ -126,52 +125,52 @@ private void initComponents() { this.answerNo4Button.setContentAreaFilled(false); this.answerNo4Button.setBorder(BorderFactory.createMatteBorder(3, 3, 0, 0, STANDARD_COLOR)); this.answerNo4Button.setFocusPainted(false); - + this.answerPanel = new JPanel(); this.answerPanel.setOpaque(false); this.answerPanel.setBorder(BorderFactory.createMatteBorder(5, 0, 0, 0, STANDARD_COLOR)); - + this.centerPanel = new JPanel(); this.centerPanel.setOpaque(false); - + this.categoryLabel = new JLabel(); this.categoryLabel.setFont(ARIAL_PLAIN_20); this.categoryLabel.setForeground(STANDARD_COLOR); - + this.currentCategoryLabel = new JLabel(); this.currentCategoryLabel.setFont(ARIAL_PLAIN_20); this.currentCategoryLabel.setForeground(STANDARD_COLOR); - + this.categoryPanel = new JPanel(); this.categoryPanel.setOpaque(false); - + this.levelLabel = new JLabel(); this.levelLabel.setFont(ARIAL_PLAIN_20); this.levelLabel.setForeground(STANDARD_COLOR); - + this.levelNo1Label = new JLabel(); this.levelNo1Label.setFont(ARIAL_PLAIN_20); - this.levelNo1Label.setForeground(Color.GREEN);//TODO muss automatisiert werden mit Frage laden - + this.levelNo1Label.setForeground(Color.GREEN);// TODO muss automatisiert werden mit Frage laden + this.levelNo2Label = new JLabel(); this.levelNo2Label.setFont(ARIAL_PLAIN_20); - this.levelNo2Label.setForeground(Color.GREEN);//TODO muss automatisiert werden mit Frage laden - + this.levelNo2Label.setForeground(Color.GREEN);// TODO muss automatisiert werden mit Frage laden + this.levelNo3Label = new JLabel(); this.levelNo3Label.setFont(ARIAL_PLAIN_20); - this.levelNo3Label.setForeground(Color.YELLOW);//TODO muss automatisiert werden mit Frage laden - + this.levelNo3Label.setForeground(Color.YELLOW);// TODO muss automatisiert werden mit Frage laden + this.levelNo4Label = new JLabel(); this.levelNo4Label.setFont(ARIAL_PLAIN_20); - this.levelNo4Label.setForeground(Color.RED);//TODO muss automatisiert werden mit Frage laden - + this.levelNo4Label.setForeground(Color.RED);// TODO muss automatisiert werden mit Frage laden + this.levelNo5Label = new JLabel(); this.levelNo5Label.setFont(ARIAL_PLAIN_20); - this.levelNo5Label.setForeground(Color.RED);//TODO muss automatisiert werden mit Frage laden - + this.levelNo5Label.setForeground(Color.RED);// TODO muss automatisiert werden mit Frage laden + this.levelPanel = new JPanel(); this.levelPanel.setOpaque(false); - + this.jokerButton = new JButton(); this.jokerButton.setBounds(15, 20, 160, 160); this.jokerButton.setFont(ARIAL_PLAIN_50); @@ -182,15 +181,15 @@ private void initComponents() { this.jokerButton.setFont(new Font("Arial", Font.PLAIN, 50)); this.jokerButton.setBorder(BorderFactory.createLineBorder(Color.CYAN, 5)); this.jokerButton.setFocusPainted(false); - + this.jokerPanel = new JPanel(); this.jokerPanel.setOpaque(false); - + this.rightPanel = new JPanel(); this.rightPanel.setOpaque(false); this.rightPanel.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 0, STANDARD_COLOR)); } - + /** * Initialisiert view layout. */ @@ -199,17 +198,17 @@ public void initLayout() { this.topPanel.add(homeButton, BorderLayout.WEST); this.topPanel.add(titleLabel, BorderLayout.CENTER); this.topPanel.add(exitButton, BorderLayout.EAST); - + this.answerPanel.setLayout(new GridLayout(2, 2)); this.answerPanel.add(answerNo1Button); this.answerPanel.add(answerNo2Button); this.answerPanel.add(answerNo3Button); this.answerPanel.add(answerNo4Button); - + this.centerPanel.setLayout(new GridLayout(2, 1)); this.centerPanel.add(questionLabel); this.centerPanel.add(answerPanel); - + this.categoryPanel.setLayout(new GridLayout(6, 1)); this.categoryPanel.add(new JLabel()); this.categoryPanel.add(new JLabel()); @@ -217,7 +216,7 @@ public void initLayout() { this.categoryPanel.add(currentCategoryLabel); this.categoryPanel.add(new JLabel()); this.categoryPanel.add(new JLabel()); - + this.levelPanel.setLayout(new GridLayout(6, 1)); this.levelPanel.add(levelLabel); this.levelPanel.add(levelNo1Label); @@ -225,159 +224,177 @@ public void initLayout() { this.levelPanel.add(levelNo3Label); this.levelPanel.add(levelNo4Label); this.levelPanel.add(levelNo5Label); - + this.jokerPanel.setLayout(null); this.jokerPanel.add(jokerButton); - + this.rightPanel.setLayout(new GridLayout(3, 1)); this.rightPanel.add(categoryPanel); this.rightPanel.add(levelPanel); this.rightPanel.add(jokerPanel); - + this.content.setLayout(new BorderLayout()); this.content.add(this.topPanel, BorderLayout.NORTH); this.content.add(this.centerPanel, BorderLayout.CENTER); this.content.add(this.rightPanel, BorderLayout.EAST); } - + /** * Gibt das Content-Panel zurueck + * * @return JPanel */ public JPanel getContent() { return this.content; } - + /** * Gibt den Home-Button zurueck + * * @return JButton */ public JButton getHomeButton() { return this.homeButton; } - + /** * Gibt das Title-Label zurueck + * * @return JLabel */ public JLabel getTitleLabel() { return this.titleLabel; } - + /** * Gibt den Exit-Button zurueck + * * @return JButton */ public JButton getExitButton() { return this.exitButton; } - + /** * Gibt das Question-Label zurueck + * * @return JLabel */ public JLabel getQuestionLabel() { return this.questionLabel; } - + /** * Gibt den AnswerNo1-Button zurueck + * * @return JButton */ public JButton getAnswerNo1Button() { return this.answerNo1Button; } - + /** * Gibt den AnswerNo2-Button zurueck + * * @return JButton */ public JButton getAnswerNo2Button() { return this.answerNo2Button; } - + /** * Gibt den AnswerNo3-Button zurueck + * * @return JButton */ public JButton getAnswerNo3Button() { return this.answerNo3Button; } - + /** * Gibt den AnswerNo4-Button zurueck + * * @return JButton */ public JButton getAnswerNo4Button() { return this.answerNo4Button; } - + /** * Gibt das Category-Label zurueck + * * @return JLabel */ public JLabel getCategoryLabel() { return this.categoryLabel; } - + /** * Gibt das CurrentCategory-Label zurueck + * * @return JLabel */ public JLabel getCurrentCategoryLabel() { return this.currentCategoryLabel; } - + /** * Gibt das Level-Label zurueck + * * @return JLabel */ public JLabel getLevelLabel() { return this.levelLabel; } - + /** * Gibt das LevelNo1-Label zurueck + * * @return JLabel */ public JLabel getLevelNo1Label() { return this.levelNo1Label; } - + /** * Gibt das LevelNo2-Label zurueck + * * @return JLabel */ public JLabel getLevelNo2Label() { return this.levelNo2Label; } - + /** * Gibt das LevelNo3-Label zurueck + * * @return JLabel */ public JLabel getLevelNo3Label() { return this.levelNo3Label; } - + /** * Gibt das LevelNo4-Label zurueck + * * @return JLabel */ public JLabel getLevelNo4Label() { return this.levelNo4Label; } - + /** * Gibt das LevelNo5-Label zurueck + * * @return JLabel */ public JLabel getLevelNo5Label() { return this.levelNo5Label; } - + /** * Gibt den Joker-Button zurueck + * * @return JButton */ public JButton getJokerButton() { diff --git a/src/view/Options.java b/src/view/Options.java index 2da5abc..40a4828 100644 --- a/src/view/Options.java +++ b/src/view/Options.java @@ -15,12 +15,11 @@ /** * - * Options ist ein view, welches JComponents - * haelt und anbietet. + * Options ist ein view, welches JComponents haelt und anbietet. */ public class Options { private JPanel content; - + private JButton homeButton; private JLabel titleLabel; private JButton exitButton; @@ -35,12 +34,12 @@ public class Options { private JButton addButton; private JButton deleteButton; private JPanel bottomPanel; - + private final Font ARIAL_BOLD_70 = new Font("Arial", Font.BOLD, 70); private final Font ARIAL_BOLD_50 = new Font("Arial", Font.BOLD, 50); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); - + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); + /** * Konstrukor zum erzeugen eines Result views. */ @@ -49,7 +48,7 @@ public Options() { this.initComponents(); this.initLayout(); } - + /** * Initialisiert components. */ @@ -61,13 +60,13 @@ private void initComponents() { this.homeButton.setContentAreaFilled(false); this.homeButton.setBorder(null); this.homeButton.setFocusPainted(false); - + this.titleLabel = new JLabel(); this.titleLabel.setHorizontalAlignment(SwingConstants.CENTER); this.titleLabel.setFont(ARIAL_BOLD_70); this.titleLabel.setForeground(STANDARD_COLOR); this.titleLabel.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 5, STANDARD_COLOR)); - + this.exitButton = new JButton(); this.exitButton.setFont(ARIAL_BOLD_70); this.exitButton.setForeground(Color.RED); @@ -75,39 +74,40 @@ private void initComponents() { this.exitButton.setContentAreaFilled(false); this.exitButton.setBorder(null); this.exitButton.setFocusPainted(false); - + this.topPanel = new JPanel(); this.topPanel.setOpaque(false); this.topPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 5, 0, STANDARD_COLOR)); - + this.checkboxFieldnameLabel = new JLabel(); this.checkboxFieldnameLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, STANDARD_COLOR)); - + this.questionFieldnameLabel = new JLabel(); this.questionFieldnameLabel.setHorizontalAlignment(SwingConstants.CENTER); this.questionFieldnameLabel.setFont(ARIAL_BOLD_50); this.questionFieldnameLabel.setForeground(STANDARD_COLOR); this.questionFieldnameLabel.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 0, STANDARD_COLOR)); - + this.categoryFieldnameLabel = new JLabel(); this.categoryFieldnameLabel.setHorizontalAlignment(SwingConstants.CENTER); this.categoryFieldnameLabel.setFont(ARIAL_BOLD_50); this.categoryFieldnameLabel.setForeground(STANDARD_COLOR); this.categoryFieldnameLabel.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, STANDARD_COLOR)); - + this.levelFieldnameLabel = new JLabel(); this.levelFieldnameLabel.setHorizontalAlignment(SwingConstants.CENTER); this.levelFieldnameLabel.setFont(ARIAL_BOLD_50); this.levelFieldnameLabel.setForeground(STANDARD_COLOR); this.levelFieldnameLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, STANDARD_COLOR)); - + this.editFieldnameLabel = new JLabel(); this.editFieldnameLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, STANDARD_COLOR)); - + this.centerPanel = new JPanel(); this.centerPanel.setOpaque(false); - - this.centerScrollPane = new JScrollPane(centerPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + + this.centerScrollPane = new JScrollPane(centerPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, + JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); this.centerScrollPane.setOpaque(false); this.centerScrollPane.getViewport().setOpaque(false); this.centerScrollPane.getVerticalScrollBar().setOpaque(false); @@ -115,7 +115,7 @@ private void initComponents() { this.centerScrollPane.getVerticalScrollBar().setBorder(null); this.centerScrollPane.getVerticalScrollBar().getComponent(0).setBackground(STANDARD_COLOR); this.centerScrollPane.getVerticalScrollBar().getComponent(1).setBackground(STANDARD_COLOR); - + this.addButton = new JButton(); this.addButton.setFont(ARIAL_BOLD_50); this.addButton.setForeground(STANDARD_COLOR); @@ -123,7 +123,7 @@ private void initComponents() { this.addButton.setContentAreaFilled(false); this.addButton.setBorder(null); this.addButton.setFocusPainted(false); - + this.deleteButton = new JButton(); this.deleteButton.setFont(ARIAL_BOLD_50); this.deleteButton.setForeground(STANDARD_COLOR); @@ -131,12 +131,12 @@ private void initComponents() { this.deleteButton.setContentAreaFilled(false); this.deleteButton.setBorder(BorderFactory.createMatteBorder(0, 5, 0, 0, STANDARD_COLOR)); this.deleteButton.setFocusPainted(false); - + this.bottomPanel = new JPanel(); this.bottomPanel.setOpaque(false); this.bottomPanel.setBorder(BorderFactory.createMatteBorder(5, 0, 0, 0, STANDARD_COLOR)); } - + /** * Initialisiert view layout. */ @@ -145,98 +145,108 @@ public void initLayout() { this.topPanel.add(homeButton, BorderLayout.WEST); this.topPanel.add(titleLabel, BorderLayout.CENTER); this.topPanel.add(exitButton, BorderLayout.EAST); - + this.centerPanel.setLayout(new GridLayout(0, 5)); this.centerPanel.add(checkboxFieldnameLabel); this.centerPanel.add(questionFieldnameLabel); this.centerPanel.add(categoryFieldnameLabel); this.centerPanel.add(levelFieldnameLabel); this.centerPanel.add(editFieldnameLabel); - + this.bottomPanel.setLayout(new GridLayout(1, 2)); this.bottomPanel.add(addButton); this.bottomPanel.add(deleteButton); - + this.content.setLayout(new BorderLayout()); this.content.add(this.topPanel, BorderLayout.NORTH); this.content.add(this.centerScrollPane, BorderLayout.CENTER); this.content.add(this.bottomPanel, BorderLayout.SOUTH); } - + /** * Gibt das Content-Panel zurueck + * * @return JPanel */ public JPanel getContent() { return this.content; } - + /** * Gibt den Home-Button zurueck + * * @return JButton */ public JButton getHomeButton() { return this.homeButton; } - + /** * Gibt das Title-Label zurueck + * * @return JLabel */ public JLabel getTitleLabel() { return this.titleLabel; } - + /** * Gibt den Exit-Button zurueck + * * @return JButton */ public JButton getExitButton() { return this.exitButton; } - + /** * Gibt das QuestionFieldname-Label zurueck + * * @return JLabel */ public JLabel getQuestionFieldnameLabel() { return this.questionFieldnameLabel; } - + /** * Gibt das CategoryFieldname-Label zurueck + * * @return JLabel */ public JLabel getCategoryFieldnameLabel() { return this.categoryFieldnameLabel; } - + /** * Gibt das LevelFieldname-Label zurueck + * * @return JLabel */ public JLabel getLevelFieldnameLabel() { return this.levelFieldnameLabel; } - + /** * Gibt das Center-Panel zurueck + * * @return JPanel */ public JPanel getCenterPanel() { return this.centerPanel; } - + /** * Gibt den Add-Button zurueck + * * @return JButton */ public JButton getAddButton() { return this.addButton; } - + /** * Gibt den Delete-Button zurueck + * * @return JButton */ public JButton getDeleteButton() { diff --git a/src/view/OptionsQuestionRow.java b/src/view/OptionsQuestionRow.java index ea6d758..dc46415 100644 --- a/src/view/OptionsQuestionRow.java +++ b/src/view/OptionsQuestionRow.java @@ -12,8 +12,8 @@ /** * - * OptionsQuestionRow ist ein view Teil von Options, welches JComponents - * haelt und anbietet. + * OptionsQuestionRow ist ein view Teil von Options, welches JComponents haelt + * und anbietet. */ public class OptionsQuestionRow { JCheckBox questionCheckBox; @@ -25,43 +25,43 @@ public class OptionsQuestionRow { private final Font ARIAL_PLAIN_20 = new Font("Arial", Font.PLAIN, 20); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); public OptionsQuestionRow() { this.initComponents(); } - + public void addItemListener(ItemListener il) { this.questionCheckBox.addItemListener(il); } - + /** * Initialisiert components. */ private void initComponents() { this.questionCheckBox = new JCheckBox(); this.questionCheckBox.setBackground(STANDARD_COLOR); - + this.checkBoxPanel = new JPanel(); this.checkBoxPanel.add(questionCheckBox); this.checkBoxPanel.setOpaque(false); this.checkBoxPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, STANDARD_COLOR)); - + this.questionLabel = new JLabel(); this.questionLabel.setFont(ARIAL_PLAIN_20); this.questionLabel.setForeground(STANDARD_COLOR); this.questionLabel.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 0, STANDARD_COLOR)); - + this.categoryLabel = new JLabel(); this.categoryLabel.setFont(ARIAL_PLAIN_20); this.categoryLabel.setForeground(STANDARD_COLOR); this.categoryLabel.setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, STANDARD_COLOR)); - + this.levelLabel = new JLabel(); this.levelLabel.setFont(ARIAL_PLAIN_20); this.levelLabel.setForeground(STANDARD_COLOR); this.levelLabel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, STANDARD_COLOR)); - + this.editButton = new JButton(); this.editButton.setFont(ARIAL_PLAIN_20); this.editButton.setForeground(STANDARD_COLOR); @@ -70,41 +70,46 @@ private void initComponents() { this.editButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, STANDARD_COLOR)); this.editButton.setFocusPainted(false); } - + /** * Gibt das CheckBox-Panel zurueck + * * @return JPanel */ public JPanel getCheckBoxPanel() { return this.checkBoxPanel; } - + /** * Gibt das Question-Label zurueck + * * @return JLabel */ public JLabel getQuestionLabel() { return this.questionLabel; } - + /** * Gibt das Category-Label zurueck + * * @return JLabel */ public JLabel getCategoryLabel() { return this.categoryLabel; } - + /** * Gibt das Level-Label zurueck + * * @return JLabel */ public JLabel getLevelLabel() { return this.levelLabel; } - + /** * Gibt den Edit-Button zurueck + * * @return JButton */ public JButton getEditButton() { diff --git a/src/view/Result.java b/src/view/Result.java index 060128a..1c45e56 100644 --- a/src/view/Result.java +++ b/src/view/Result.java @@ -11,12 +11,11 @@ /** * - * Result ist ein view, welches JComponents - * haelt und anbietet. + * Result ist ein view, welches JComponents haelt und anbietet. */ public class Result { private JPanel content; - + private JLabel resultLabel; private JLabel levelLeftLabel; private JLabel levelRightLabel; @@ -32,13 +31,13 @@ public class Result { private JButton homeButton; private JButton exitButton; private JPanel buttonPanel; - + private final Font ARIAL_BOLD_100 = new Font("Arial", Font.BOLD, 100); private final Font ARIAL_PLAIN_50 = new Font("Arial", Font.PLAIN, 50); private final Font ARIAL_PLAIN_30 = new Font("Arial", Font.PLAIN, 30); private final Color STANDARD_COLOR = Color.CYAN; - private final Color TRANSPARENT_COLOR = new Color(0,0,0,0); - + private final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0); + /** * Konstrukor zum erzeugen eines Start views. */ @@ -47,7 +46,7 @@ public Result() { this.initComponents(); this.initLayout(); } - + /** * Initialisiert components. */ @@ -56,50 +55,50 @@ private void initComponents() { this.resultLabel.setHorizontalAlignment(SwingConstants.CENTER); this.resultLabel.setFont(ARIAL_BOLD_100); this.resultLabel.setForeground(Color.RED); - + this.levelLeftLabel = new JLabel(); this.levelLeftLabel.setFont(ARIAL_PLAIN_30); this.levelLeftLabel.setForeground(STANDARD_COLOR); - + this.levelRightLabel = new JLabel(); this.levelRightLabel.setFont(ARIAL_PLAIN_30); this.levelRightLabel.setForeground(STANDARD_COLOR); - + this.scoreLeftLabel = new JLabel(); this.scoreLeftLabel.setFont(ARIAL_PLAIN_30); this.scoreLeftLabel.setForeground(STANDARD_COLOR); - + this.scoreRightLabel = new JLabel(); this.scoreRightLabel.setFont(ARIAL_PLAIN_30); this.scoreRightLabel.setForeground(STANDARD_COLOR); - + this.questionLeftLabel = new JLabel(); this.questionLeftLabel.setFont(ARIAL_PLAIN_30); this.questionLeftLabel.setForeground(STANDARD_COLOR); - + this.questionRightLabel = new JLabel(); this.questionRightLabel.setFont(ARIAL_PLAIN_30); this.questionRightLabel.setForeground(STANDARD_COLOR); - + this.playerAnswerLeftLabel = new JLabel(); this.playerAnswerLeftLabel.setFont(ARIAL_PLAIN_30); this.playerAnswerLeftLabel.setForeground(STANDARD_COLOR); - + this.playerAnswerRightLabel = new JLabel(); this.playerAnswerRightLabel.setFont(ARIAL_PLAIN_30); this.playerAnswerRightLabel.setForeground(STANDARD_COLOR); - + this.correctAnswerLeftLabel = new JLabel(); this.correctAnswerLeftLabel.setFont(ARIAL_PLAIN_30); this.correctAnswerLeftLabel.setForeground(STANDARD_COLOR); - + this.correctAnswerRightLabel = new JLabel(); this.correctAnswerRightLabel.setFont(ARIAL_PLAIN_30); this.correctAnswerRightLabel.setForeground(STANDARD_COLOR); - + this.resultPanel = new JPanel(); this.resultPanel.setOpaque(false); - + this.homeButton = new JButton(); this.homeButton.setFont(ARIAL_PLAIN_50); this.homeButton.setForeground(STANDARD_COLOR); @@ -107,7 +106,7 @@ private void initComponents() { this.homeButton.setContentAreaFilled(false); this.homeButton.setBorder(null); this.homeButton.setFocusPainted(false); - + this.exitButton = new JButton(); this.exitButton.setFont(ARIAL_PLAIN_50); this.exitButton.setForeground(STANDARD_COLOR); @@ -115,11 +114,11 @@ private void initComponents() { this.exitButton.setContentAreaFilled(false); this.exitButton.setBorder(null); this.exitButton.setFocusPainted(false); - + this.buttonPanel = new JPanel(); this.buttonPanel.setOpaque(false); } - + /** * Initialisiert view layout. */ @@ -135,123 +134,137 @@ private void initLayout() { this.resultPanel.add(playerAnswerRightLabel); this.resultPanel.add(correctAnswerLeftLabel); this.resultPanel.add(correctAnswerRightLabel); - + this.buttonPanel.setLayout(new GridLayout(2, 1)); this.buttonPanel.add(homeButton); this.buttonPanel.add(exitButton); - + this.content.setLayout(new GridLayout(3, 1)); this.content.add(resultLabel); this.content.add(resultPanel); this.content.add(buttonPanel); } - + /** * Gibt das Content-Panel zurueck + * * @return JPanel */ public JPanel getContent() { return this.content; } - + /** * Gibt das Result-Label zurueck + * * @return JLabel */ public JLabel getResultLabel() { return this.resultLabel; } - + /** * Gibt das LevelLeft-Label zurueck + * * @return JLabel */ public JLabel getLevelLeftLabel() { return this.levelLeftLabel; } - + /** * Gibt das LevelRight-Label zurueck + * * @return JLabel */ public JLabel getLevelRightLabel() { return this.levelRightLabel; } - + /** * Gibt das ScoreLeft-Label zurueck + * * @return JLabel */ public JLabel getScoreLeftLabel() { return this.scoreLeftLabel; } - + /** * Gibt das ScoreRight-Label zurueck + * * @return JLabel */ public JLabel getScoreRightLabel() { return this.scoreRightLabel; } - + /** * Gibt das QuestionLeft-Label zurueck + * * @return JLabel */ public JLabel getQuestionLeftLabel() { return this.questionLeftLabel; } - + /** * Gibt das QuestionRight-Label zurueck + * * @return JLabel */ public JLabel getQuestionRightLabel() { return this.questionRightLabel; } - + /** * Gibt das PlayerAnswerLeft-Label zurueck + * * @return JLabel */ public JLabel getPlayerAnswerLeftLabel() { return this.playerAnswerLeftLabel; } - + /** * Gibt das PlayerAnswerRight-Label zurueck + * * @return JLabel */ public JLabel getPlayerAnswerRightLabel() { return this.playerAnswerRightLabel; } - + /** * Gibt das CorrectAnswerLeft-Label zurueck + * * @return JLabel */ public JLabel getCorrectAnswerLeftLabel() { return this.correctAnswerLeftLabel; } - + /** * Gibt das CorrectAnswerRight-Label zurueck + * * @return JLabel */ public JLabel getCorrectAnswerRightLabel() { return this.correctAnswerRightLabel; } - + /** * Gibt den Home-Button zurueck + * * @return JButton */ public JButton getHomeButton() { return this.homeButton; } - + /** * Gibt den Exit-Button zurueck + * * @return JButton */ public JButton getExitButton() {