From 716331f19bb76dd16c38dd7d251401bb8c4c8076 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 12:02:10 +0100 Subject: [PATCH 01/21] Test Quersumme --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 00e5c38..8da67c4 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -103,6 +103,17 @@ class TasksFrameTest { assertEquals(1,p3); } + @Test + void test_quer(){ + TasksFrame tasksFrame = new TasksFrame(); + int q = tasksFrame.quer(15); + assertEquals(6, q); + int q2 = tasksFrame.quer(23); + assertEquals(5, q2); + int q3 = tasksFrame.quer(235); + assertEquals(10, q3); + + } } From ea085e0631d73cb99ad9918021578bff8b0285f0 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 12:39:26 +0100 Subject: [PATCH 02/21] kgV Function added --- src/main/java/src/TasksFrame.java | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index ed4f91f..f01a0b0 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -79,6 +79,52 @@ public class TasksFrame extends JFrame { setupQuersumme(); + setupKgV(); + + } + + private void setupKgV() { + JPanel jPanel = setupPanel("kgV"); + + JButton button = new JButton("kgV"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + + JTextField a = new JTextField(); + a.setBounds(10, 40, 30, 20); + a.setVisible(true); + + JTextField b = new JTextField(); + b.setBounds(50, 40, 30, 20); + b.setVisible(true); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10,90,60,30); + + jPanel.add(button); + jPanel.add(a); + jPanel.add(b); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String texta = a.getText(); + String textb = b.getText(); + Integer val_a = Integer.valueOf(texta); + Integer val_b = Integer.valueOf(textb); + int res = kgV(val_a, val_b); + jLabel.setText(String.valueOf(res)); + } + }); + + + } + + public int kgV(int a, int b) { + int kgV= (a*b)/ggt(a,b); + return kgV; } private void setupQuersumme() { From 6371f822403214b30100dac15e9d76dac22acfa5 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 12:39:27 +0100 Subject: [PATCH 03/21] wrote sandbox --- src/main/java/src/MainFrame.java | 1 + src/main/java/src/Model.java | 4 + src/main/java/src/SandboxFrame.java | 222 +++++++++++++++++++++++++- src/test/java/src/TasksFrameTest.java | 2 +- 4 files changed, 227 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index 0071c01..0fbde13 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -97,6 +97,7 @@ public class MainFrame extends JFrame { private JPanel setupNums(String number) { + JPanel jPanel = new JPanel(); jPanel.setBackground(Color.BLUE); jPanel.setVisible(true); diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index 57ebad5..bfed87c 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -348,4 +348,8 @@ public class Model { throw new RuntimeException(e); } } + + public void createNewGame(String difficulty) { + + } } diff --git a/src/main/java/src/SandboxFrame.java b/src/main/java/src/SandboxFrame.java index 0d2a89a..4fffa86 100644 --- a/src/main/java/src/SandboxFrame.java +++ b/src/main/java/src/SandboxFrame.java @@ -1,15 +1,235 @@ package src; import javax.swing.*; +import javax.swing.border.LineBorder; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; public class SandboxFrame extends JFrame { + private GameField gameField; + private JPanel rootPanel; + + private String difficulty = "easy"; + public void run() { this.setLayout(null); this.setVisible(true); - this.setBounds(400, 200, 500, 500); + this.setBounds(400, 200, 500, 550); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setupLayout(); + + } + + private void setupLayout() { + + rootPanel = new JPanel(); + rootPanel.setVisible(true); + rootPanel.setBounds(0, 0, 500, 500); + rootPanel.setBackground(Color.LIGHT_GRAY); + rootPanel.setLayout(null); + this.setContentPane(rootPanel); + + JPanel header = setupHeader(20, 10); + header.setBounds(125, 5, 250, 50); + rootPanel.add(header); + + gameField = new GameField(360); + gameField.setBounds(70, 50, 360, 360); + rootPanel.add(gameField); + + JPanel diff = setupDifficulty(); + diff.setBounds(80, 420, 300, 35); + rootPanel.add(diff); + + JButton saveBtn = setupSaveButton(); + saveBtn.setBounds(400, 420, 100, 30); + rootPanel.add(saveBtn); + + JPanel numberField = setupNumberField(); + numberField.setBounds(100, 470, 300, 35); + + rootPanel.add(numberField); + } + + private JButton setupSaveButton() { + JButton save = new JButton("Save"); + save.setVisible(true); + + save.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + Model model = new Model(gameField); + model.createNewGame(difficulty); + + SandboxFrame.this.dispose(); + + } + }); + return save; + } + + private JPanel setupNumberField() { + + JPanel boxPanel = setupJPanel(); + boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.X_AXIS)); + + JPanel jPanel1 = setupNums("1"); + boxPanel.add(jPanel1); + + JPanel jPanel2 = setupNums("2"); + boxPanel.add(jPanel2); + + JPanel jPanel3 = setupNums("3"); + boxPanel.add(jPanel3); + + JPanel jPanel4 = setupNums("4"); + boxPanel.add(jPanel4); + + JPanel jPanel5 = setupNums("5"); + boxPanel.add(jPanel5); + + JPanel jPanel6 = setupNums("6"); + boxPanel.add(jPanel6); + + JPanel jPanel7 = setupNums("7"); + boxPanel.add(jPanel7); + + JPanel jPanel8 = setupNums("8"); + boxPanel.add(jPanel8); + + JPanel jPanel9 = setupNums("9"); + boxPanel.add(jPanel9); + + return boxPanel; + } + + private JPanel setupDifficulty() { + + JPanel jPanel = new JPanel(); + jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.X_AXIS)); + + JButton easy = new JButton("Easy"); + easy.setPreferredSize(new Dimension(100, 30)); + easy.setVisible(true); + jPanel.add(easy); + + easy.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "easy"; + } + }); + + jPanel.add(Box.createHorizontalStrut(10)); + + JButton medium = new JButton("Medium"); + medium.setPreferredSize(new Dimension(100, 30)); + medium.setVisible(true); + jPanel.add(medium); + medium.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "medium"; + } + }); + + jPanel.add(Box.createHorizontalStrut(10)); + + JButton hard = new JButton("Hard"); + hard.setPreferredSize(new Dimension(100, 30)); + hard.setVisible(true); + jPanel.add(hard); + hard.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + difficulty = "hard"; + } + }); + + + return jPanel; + } + + private JPanel setupHeader(int headerSize, int subheaderSize) { + + JPanel jPanel = new JPanel(); + jPanel.setVisible(true); + jPanel.setBackground(new Color(0, 0, 0, 0)); + jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); + + JLabel header = new JLabel(); + header.setAlignmentX(Component.CENTER_ALIGNMENT); + header.setText("Sudoku Sandbox"); + header.setVisible(true); + header.setForeground(Color.BLACK); + header.setFont(new Font("Times New Roman", Font.BOLD, headerSize)); + jPanel.add(header); + + JLabel subheader = new JLabel(); + subheader.setAlignmentX(Component.CENTER_ALIGNMENT); + subheader.setText("Represented by Team Deep Thought"); + subheader.setVisible(true); + subheader.setForeground(Color.BLACK); + subheader.setFont(new Font("Times New Roman", Font.ITALIC, subheaderSize)); + jPanel.add(subheader); + + return jPanel; + } + + private JPanel setupNums(String number) { + + JPanel jPanel = new JPanel(); + jPanel.setBackground(Color.BLUE); + jPanel.setVisible(true); + jPanel.setBorder(new LineBorder(Color.PINK, 1)); + jPanel.addMouseListener(new MouseListener() { + @Override + public void mouseClicked(MouseEvent e) { + + } + + @Override + public void mousePressed(MouseEvent e) { + gameField.getActivePanel().setValue(Integer.valueOf(number)); + + } + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + }); + JLabel numLabel1 = new JLabel(); + numLabel1.setText(number); + numLabel1.setLayout(null); + numLabel1.setVisible(true); + jPanel.add(numLabel1); + + return jPanel; + } + + public JPanel setupJPanel() { + JPanel panel = new JPanel(); + panel.setBounds(100, 450, 300, 30); + panel.setVisible(true); + panel.setBackground(Color.GREEN); + return panel; } } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 00e5c38..d20745d 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -103,7 +103,7 @@ class TasksFrameTest { assertEquals(1,p3); } - } +} From 3ba98ddd3badc0ab82842f19fe99ea7d08602090 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 12:46:35 +0100 Subject: [PATCH 04/21] added deleted test back to project --- src/main/java/src/Model.java | 2 ++ src/test/java/src/TasksFrameTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index bfed87c..302f9b5 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -350,6 +350,8 @@ public class Model { } public void createNewGame(String difficulty) { + JSONObject jsonObject = modelToJson(); + } } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index d20745d..5eef25f 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -103,6 +103,18 @@ class TasksFrameTest { assertEquals(1,p3); } + @Test + void test_quer(){ + TasksFrame tasksFrame = new TasksFrame(); + int q = tasksFrame.quer(15); + assertEquals(6, q); + int q2 = tasksFrame.quer(23); + assertEquals(5, q2); + int q3 = tasksFrame.quer(235); + assertEquals(10, q3); + + } + } From 1fb4d1648ca895babe2a5a7679b061f872e89608 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 12:53:27 +0100 Subject: [PATCH 05/21] kgV Test --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 5eef25f..ea4a96b 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -115,6 +115,17 @@ class TasksFrameTest { } + @Test + void test_kgV(){ + TasksFrame tasksFrame = new TasksFrame(); + int a = tasksFrame.kgV(5, 8); + assertEquals(40, a); + int b = tasksFrame.kgV(28, 64); + assertEquals(448, b); + int c = tasksFrame.kgV(35, 70); + assertEquals(70, c); + } + } From a939b97992b9b96ecaf8be9f5ce0de74ee1332f3 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 13:48:33 +0100 Subject: [PATCH 06/21] =?UTF-8?q?Runde=20Summe=20Function=20added,=20die?= =?UTF-8?q?=20die=20Summe=20der=20auf=20Zehner=20gerundeten=20Werte=20von?= =?UTF-8?q?=20a,=20b=20und=20c=20zur=C3=BCckgibt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/src/TasksFrame.java | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index f01a0b0..39b80f9 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -80,9 +80,70 @@ public class TasksFrame extends JFrame { setupQuersumme(); setupKgV(); + setupRoundSum(); } + private void setupRoundSum() { + JPanel jPanel = setupPanel("Runde Summe"); + + JButton button = new JButton("round sum"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + + JTextField a = new JTextField(); + a.setBounds(10, 40, 30, 20); + a.setVisible(true); + + JTextField b = new JTextField(); + b.setBounds(50, 40, 30, 20); + b.setVisible(true); + + JTextField c = new JTextField(); + c.setBounds(90, 40, 30, 20); + c.setVisible(true); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10,90,60,30); + + jPanel.add(button); + jPanel.add(a); + jPanel.add(b); + jPanel.add(c); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String texta = a.getText(); + String textb = b.getText(); + String textc = c.getText(); + Integer val_a = Integer.valueOf(texta); + Integer val_b = Integer.valueOf(textb); + Integer val_c = Integer.valueOf(textc); + int res = roundSum(val_a, val_b, val_c); + jLabel.setText(String.valueOf(res)); + } + }); + } + + public int roundSum(int a, int b, int c) { + + return runde10(a) + runde10(b) + runde10(c); + + } + + public int runde10(int n) { + if (n % 10 >= 5) { + return n + 10 - n % 10; + } + else { + return n - n % 10; + } + } + + private void setupKgV() { JPanel jPanel = setupPanel("kgV"); From 4c2835706078145d53a52c8e988ed9b1bc690331 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 13:54:52 +0100 Subject: [PATCH 07/21] its now possible to create a new game in sandbox whicht will be saved in our sudoku.json file --- src/main/java/src/Model.java | 70 ++++++++++++++++++++++++++++------- src/main/java/src/sudoku.json | 2 +- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index 302f9b5..7fae807 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -100,7 +100,6 @@ public class Model { public static String loadAllData() { - File file = new File("src/main/java/src/sudoku.json"); if (file.exists()) { @@ -110,6 +109,7 @@ public class Model { throw new RuntimeException(e); } } + String line = ""; try { Scanner scanner = new Scanner(file); @@ -120,6 +120,22 @@ public class Model { } catch (FileNotFoundException e) { throw new RuntimeException(e); } + + if (line.equals("")) { + initJsonFile(); + } + + line = ""; + try { + Scanner scanner = new Scanner(file); + while (scanner.hasNextLine()) { + line = line + scanner.nextLine(); + + } + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + return line; } @@ -155,18 +171,6 @@ public class Model { } } - public void loadNewMedium() { - - } - - public void loadNewHard() { - - } - - public void safeNewSandboxGame() { - - } - @Override public String toString() { @@ -350,8 +354,46 @@ public class Model { } public void createNewGame(String difficulty) { - JSONObject jsonObject = modelToJson(); + JSONObject myNewGame = modelToJson(); + String s = loadAllData(); + + JSONObject object = null; + try { + object = (JSONObject) new JSONParser().parse(s); + } catch (ParseException e) { + throw new RuntimeException(e); + } + + JSONArray easyArray = (JSONArray) object.get("easyGame"); + JSONArray mediumArray = (JSONArray) object.get("mediumGame"); + JSONArray hardArray = (JSONArray) object.get("hardGame"); + + System.out.println(); + + if (difficulty.equals("easy")) { + + easyArray.add(myNewGame); + + } else if (difficulty.equals("medium")) { + + mediumArray.add(myNewGame); + + } else if (difficulty.equals("hard")) { + + hardArray.add(myNewGame); + + } + + String jsonString = object.toJSONString(); + + try { + FileWriter writer = new FileWriter("src/main/java/src/sudoku.json"); + writer.write(jsonString); + writer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/src/sudoku.json b/src/main/java/src/sudoku.json index 6d5978b..aae89e3 100644 --- a/src/main/java/src/sudoku.json +++ b/src/main/java/src/sudoku.json @@ -1 +1 @@ -{"mediumGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":1},{"x":4,"y":3,"value":1},{"x":5,"y":3,"value":1},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":1},{"x":4,"y":4,"value":1},{"x":5,"y":4,"value":1},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":1},{"x":4,"y":5,"value":1},{"x":5,"y":5,"value":1},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"easyGame":[{"values":[{"x":0,"y":0,"value":1},{"x":1,"y":0,"value":1},{"x":2,"y":0,"value":1},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":1},{"x":1,"y":1,"value":1},{"x":2,"y":1,"value":1},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":1},{"x":1,"y":2,"value":1},{"x":2,"y":2,"value":1},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"hardGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":1},{"x":7,"y":6,"value":1},{"x":8,"y":6,"value":1},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":1},{"x":7,"y":7,"value":1},{"x":8,"y":7,"value":1},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":1},{"x":7,"y":8,"value":1},{"x":8,"y":8,"value":1}]}]} \ No newline at end of file +{"mediumGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":1},{"x":4,"y":3,"value":1},{"x":5,"y":3,"value":1},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":1},{"x":4,"y":4,"value":1},{"x":5,"y":4,"value":1},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":1},{"x":4,"y":5,"value":1},{"x":5,"y":5,"value":1},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"easyGame":[{"values":[{"x":0,"y":0,"value":1},{"x":1,"y":0,"value":1},{"x":2,"y":0,"value":1},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":1},{"x":1,"y":1,"value":1},{"x":2,"y":1,"value":1},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":1},{"x":1,"y":2,"value":1},{"x":2,"y":2,"value":1},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]},{"values":[{"x":0,"y":0,"value":-1},{"x":1,"y":0,"value":-1},{"x":2,"y":0,"value":-1},{"x":3,"y":0,"value":-1},{"x":4,"y":0,"value":-1},{"x":5,"y":0,"value":-1},{"x":6,"y":0,"value":-1},{"x":7,"y":0,"value":-1},{"x":8,"y":0,"value":-1},{"x":0,"y":1,"value":-1},{"x":1,"y":1,"value":-1},{"x":2,"y":1,"value":-1},{"x":3,"y":1,"value":-1},{"x":4,"y":1,"value":-1},{"x":5,"y":1,"value":-1},{"x":6,"y":1,"value":-1},{"x":7,"y":1,"value":-1},{"x":8,"y":1,"value":-1},{"x":0,"y":2,"value":-1},{"x":1,"y":2,"value":-1},{"x":2,"y":2,"value":-1},{"x":3,"y":2,"value":-1},{"x":4,"y":2,"value":-1},{"x":5,"y":2,"value":-1},{"x":6,"y":2,"value":-1},{"x":7,"y":2,"value":-1},{"x":8,"y":2,"value":-1},{"x":0,"y":3,"value":-1},{"x":1,"y":3,"value":-1},{"x":2,"y":3,"value":1},{"x":3,"y":3,"value":-1},{"x":4,"y":3,"value":-1},{"x":5,"y":3,"value":-1},{"x":6,"y":3,"value":-1},{"x":7,"y":3,"value":-1},{"x":8,"y":3,"value":-1},{"x":0,"y":4,"value":-1},{"x":1,"y":4,"value":-1},{"x":2,"y":4,"value":-1},{"x":3,"y":4,"value":-1},{"x":4,"y":4,"value":-1},{"x":5,"y":4,"value":-1},{"x":6,"y":4,"value":-1},{"x":7,"y":4,"value":-1},{"x":8,"y":4,"value":-1},{"x":0,"y":5,"value":-1},{"x":1,"y":5,"value":-1},{"x":2,"y":5,"value":-1},{"x":3,"y":5,"value":-1},{"x":4,"y":5,"value":-1},{"x":5,"y":5,"value":-1},{"x":6,"y":5,"value":-1},{"x":7,"y":5,"value":-1},{"x":8,"y":5,"value":-1},{"x":0,"y":6,"value":-1},{"x":1,"y":6,"value":-1},{"x":2,"y":6,"value":-1},{"x":3,"y":6,"value":-1},{"x":4,"y":6,"value":-1},{"x":5,"y":6,"value":2},{"x":6,"y":6,"value":-1},{"x":7,"y":6,"value":-1},{"x":8,"y":6,"value":-1},{"x":0,"y":7,"value":-1},{"x":1,"y":7,"value":-1},{"x":2,"y":7,"value":-1},{"x":3,"y":7,"value":-1},{"x":4,"y":7,"value":-1},{"x":5,"y":7,"value":-1},{"x":6,"y":7,"value":-1},{"x":7,"y":7,"value":-1},{"x":8,"y":7,"value":-1},{"x":0,"y":8,"value":-1},{"x":1,"y":8,"value":-1},{"x":2,"y":8,"value":-1},{"x":3,"y":8,"value":-1},{"x":4,"y":8,"value":-1},{"x":5,"y":8,"value":-1},{"x":6,"y":8,"value":-1},{"x":7,"y":8,"value":-1},{"x":8,"y":8,"value":-1}]}],"hardGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":1},{"x":7,"y":6,"value":1},{"x":8,"y":6,"value":1},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":1},{"x":7,"y":7,"value":1},{"x":8,"y":7,"value":1},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":1},{"x":7,"y":8,"value":1},{"x":8,"y":8,"value":1}]}]} \ No newline at end of file From 1e1b628443d486c09d75ea5b20412900afbdc382 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 13:55:48 +0100 Subject: [PATCH 08/21] Round Sum Test --- src/main/java/src/TasksFrame.java | 4 ++-- src/test/java/src/TasksFrameTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 39b80f9..0c367fd 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -130,11 +130,11 @@ public class TasksFrame extends JFrame { public int roundSum(int a, int b, int c) { - return runde10(a) + runde10(b) + runde10(c); + return round10(a) + round10(b) + round10(c); } - public int runde10(int n) { + public int round10(int n) { if (n % 10 >= 5) { return n + 10 - n % 10; } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ea4a96b..ca296e1 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -126,6 +126,16 @@ class TasksFrameTest { assertEquals(70, c); } + @Test + void test_roundSum(){ + TasksFrame tasksFrame = new TasksFrame(); + int a = tasksFrame.roundSum(15, 21, 12); + assertEquals(50, a); + int b = tasksFrame.roundSum(48, 25, 17); + assertEquals(100, b); + int c = tasksFrame.roundSum(13, 9, 26); + assertEquals(50, c); + } } From b94c310149ba2d99a4c1b6dcbe3fe6c1da04554c Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 14:01:11 +0100 Subject: [PATCH 09/21] Round10 Function Test --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ca296e1..4af998f 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -136,6 +136,17 @@ class TasksFrameTest { int c = tasksFrame.roundSum(13, 9, 26); assertEquals(50, c); } + + @Test + void test_round10(){ + TasksFrame tasksFrame = new TasksFrame(); + int a = tasksFrame.round10(15); + assertEquals(20, a); + int b = tasksFrame.round10(56); + assertEquals(60, b); + int c = tasksFrame.round10(12); + assertEquals(10, c); + } } From f7eff66f440e7fd427d3e0aedc52a0f60e52e817 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 14:28:37 +0100 Subject: [PATCH 10/21] load a easy game to the gamefield --- src/main/java/src/MainFrame.java | 29 +++++++++++++++++++++++++++-- src/main/java/src/Model.java | 1 + src/main/java/src/sudoku.json | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index 0fbde13..f9b2d7c 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -1,5 +1,10 @@ package src; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + import javax.swing.*; import javax.swing.border.LineBorder; import java.awt.*; @@ -12,6 +17,9 @@ public class MainFrame extends JFrame { private GameField gameField; + private JSONArray currentGameDifficulty; + private Model currentModel; + public void run() { this.setLayout(null); @@ -36,7 +44,6 @@ public class MainFrame extends JFrame { gameField.setBounds(70, 50, 360, 360); rootPanel.add(gameField); - int j = 0; JPanel boxPanel = setupJPanel(); @@ -138,7 +145,6 @@ public class MainFrame extends JFrame { return jPanel; } - public JPanel setupJPanel() { JPanel panel = new JPanel(); panel.setBounds(100, 450, 300, 30); @@ -173,6 +179,10 @@ public class MainFrame extends JFrame { return jPanel; } + private void loadDataToGameField(JSONObject jsonObject) { + currentModel = new Model(jsonObject, gameField); + } + private JMenuBar setupMenuBar() { JMenuBar menu_mb=new JMenuBar(); @@ -184,6 +194,21 @@ public class MainFrame extends JFrame { JMenuItem menu_i1=new JMenuItem("Nochmal"); JMenuItem menu_i2=new JMenuItem("Tipp"); JMenuItem menu_i4=new JMenuItem("Einfach"); + menu_i4.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String data = Model.loadAllData(); + JSONObject object = null; + try { + object = (JSONObject)new JSONParser().parse(data); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + currentGameDifficulty = (JSONArray) object.get("easyGame"); + loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); + } + }); + JMenuItem menu_i5=new JMenuItem("Mittel"); JMenuItem menu_i6=new JMenuItem("Schwer"); diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index 7fae807..66c659a 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -370,6 +370,7 @@ public class Model { JSONArray mediumArray = (JSONArray) object.get("mediumGame"); JSONArray hardArray = (JSONArray) object.get("hardGame"); + System.out.println(); if (difficulty.equals("easy")) { diff --git a/src/main/java/src/sudoku.json b/src/main/java/src/sudoku.json index aae89e3..6d5978b 100644 --- a/src/main/java/src/sudoku.json +++ b/src/main/java/src/sudoku.json @@ -1 +1 @@ -{"mediumGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":1},{"x":4,"y":3,"value":1},{"x":5,"y":3,"value":1},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":1},{"x":4,"y":4,"value":1},{"x":5,"y":4,"value":1},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":1},{"x":4,"y":5,"value":1},{"x":5,"y":5,"value":1},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"easyGame":[{"values":[{"x":0,"y":0,"value":1},{"x":1,"y":0,"value":1},{"x":2,"y":0,"value":1},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":1},{"x":1,"y":1,"value":1},{"x":2,"y":1,"value":1},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":1},{"x":1,"y":2,"value":1},{"x":2,"y":2,"value":1},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]},{"values":[{"x":0,"y":0,"value":-1},{"x":1,"y":0,"value":-1},{"x":2,"y":0,"value":-1},{"x":3,"y":0,"value":-1},{"x":4,"y":0,"value":-1},{"x":5,"y":0,"value":-1},{"x":6,"y":0,"value":-1},{"x":7,"y":0,"value":-1},{"x":8,"y":0,"value":-1},{"x":0,"y":1,"value":-1},{"x":1,"y":1,"value":-1},{"x":2,"y":1,"value":-1},{"x":3,"y":1,"value":-1},{"x":4,"y":1,"value":-1},{"x":5,"y":1,"value":-1},{"x":6,"y":1,"value":-1},{"x":7,"y":1,"value":-1},{"x":8,"y":1,"value":-1},{"x":0,"y":2,"value":-1},{"x":1,"y":2,"value":-1},{"x":2,"y":2,"value":-1},{"x":3,"y":2,"value":-1},{"x":4,"y":2,"value":-1},{"x":5,"y":2,"value":-1},{"x":6,"y":2,"value":-1},{"x":7,"y":2,"value":-1},{"x":8,"y":2,"value":-1},{"x":0,"y":3,"value":-1},{"x":1,"y":3,"value":-1},{"x":2,"y":3,"value":1},{"x":3,"y":3,"value":-1},{"x":4,"y":3,"value":-1},{"x":5,"y":3,"value":-1},{"x":6,"y":3,"value":-1},{"x":7,"y":3,"value":-1},{"x":8,"y":3,"value":-1},{"x":0,"y":4,"value":-1},{"x":1,"y":4,"value":-1},{"x":2,"y":4,"value":-1},{"x":3,"y":4,"value":-1},{"x":4,"y":4,"value":-1},{"x":5,"y":4,"value":-1},{"x":6,"y":4,"value":-1},{"x":7,"y":4,"value":-1},{"x":8,"y":4,"value":-1},{"x":0,"y":5,"value":-1},{"x":1,"y":5,"value":-1},{"x":2,"y":5,"value":-1},{"x":3,"y":5,"value":-1},{"x":4,"y":5,"value":-1},{"x":5,"y":5,"value":-1},{"x":6,"y":5,"value":-1},{"x":7,"y":5,"value":-1},{"x":8,"y":5,"value":-1},{"x":0,"y":6,"value":-1},{"x":1,"y":6,"value":-1},{"x":2,"y":6,"value":-1},{"x":3,"y":6,"value":-1},{"x":4,"y":6,"value":-1},{"x":5,"y":6,"value":2},{"x":6,"y":6,"value":-1},{"x":7,"y":6,"value":-1},{"x":8,"y":6,"value":-1},{"x":0,"y":7,"value":-1},{"x":1,"y":7,"value":-1},{"x":2,"y":7,"value":-1},{"x":3,"y":7,"value":-1},{"x":4,"y":7,"value":-1},{"x":5,"y":7,"value":-1},{"x":6,"y":7,"value":-1},{"x":7,"y":7,"value":-1},{"x":8,"y":7,"value":-1},{"x":0,"y":8,"value":-1},{"x":1,"y":8,"value":-1},{"x":2,"y":8,"value":-1},{"x":3,"y":8,"value":-1},{"x":4,"y":8,"value":-1},{"x":5,"y":8,"value":-1},{"x":6,"y":8,"value":-1},{"x":7,"y":8,"value":-1},{"x":8,"y":8,"value":-1}]}],"hardGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":1},{"x":7,"y":6,"value":1},{"x":8,"y":6,"value":1},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":1},{"x":7,"y":7,"value":1},{"x":8,"y":7,"value":1},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":1},{"x":7,"y":8,"value":1},{"x":8,"y":8,"value":1}]}]} \ No newline at end of file +{"mediumGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":1},{"x":4,"y":3,"value":1},{"x":5,"y":3,"value":1},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":1},{"x":4,"y":4,"value":1},{"x":5,"y":4,"value":1},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":1},{"x":4,"y":5,"value":1},{"x":5,"y":5,"value":1},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"easyGame":[{"values":[{"x":0,"y":0,"value":1},{"x":1,"y":0,"value":1},{"x":2,"y":0,"value":1},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":1},{"x":1,"y":1,"value":1},{"x":2,"y":1,"value":1},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":1},{"x":1,"y":2,"value":1},{"x":2,"y":2,"value":1},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":0},{"x":7,"y":6,"value":0},{"x":8,"y":6,"value":0},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":0},{"x":7,"y":7,"value":0},{"x":8,"y":7,"value":0},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":0},{"x":7,"y":8,"value":0},{"x":8,"y":8,"value":0}]}],"hardGame":[{"values":[{"x":0,"y":0,"value":0},{"x":1,"y":0,"value":0},{"x":2,"y":0,"value":0},{"x":3,"y":0,"value":0},{"x":4,"y":0,"value":0},{"x":5,"y":0,"value":0},{"x":6,"y":0,"value":0},{"x":7,"y":0,"value":0},{"x":8,"y":0,"value":0},{"x":0,"y":1,"value":0},{"x":1,"y":1,"value":0},{"x":2,"y":1,"value":0},{"x":3,"y":1,"value":0},{"x":4,"y":1,"value":0},{"x":5,"y":1,"value":0},{"x":6,"y":1,"value":0},{"x":7,"y":1,"value":0},{"x":8,"y":1,"value":0},{"x":0,"y":2,"value":0},{"x":1,"y":2,"value":0},{"x":2,"y":2,"value":0},{"x":3,"y":2,"value":0},{"x":4,"y":2,"value":0},{"x":5,"y":2,"value":0},{"x":6,"y":2,"value":0},{"x":7,"y":2,"value":0},{"x":8,"y":2,"value":0},{"x":0,"y":3,"value":0},{"x":1,"y":3,"value":0},{"x":2,"y":3,"value":0},{"x":3,"y":3,"value":0},{"x":4,"y":3,"value":0},{"x":5,"y":3,"value":0},{"x":6,"y":3,"value":0},{"x":7,"y":3,"value":0},{"x":8,"y":3,"value":0},{"x":0,"y":4,"value":0},{"x":1,"y":4,"value":0},{"x":2,"y":4,"value":0},{"x":3,"y":4,"value":0},{"x":4,"y":4,"value":0},{"x":5,"y":4,"value":0},{"x":6,"y":4,"value":0},{"x":7,"y":4,"value":0},{"x":8,"y":4,"value":0},{"x":0,"y":5,"value":0},{"x":1,"y":5,"value":0},{"x":2,"y":5,"value":0},{"x":3,"y":5,"value":0},{"x":4,"y":5,"value":0},{"x":5,"y":5,"value":0},{"x":6,"y":5,"value":0},{"x":7,"y":5,"value":0},{"x":8,"y":5,"value":0},{"x":0,"y":6,"value":0},{"x":1,"y":6,"value":0},{"x":2,"y":6,"value":0},{"x":3,"y":6,"value":0},{"x":4,"y":6,"value":0},{"x":5,"y":6,"value":0},{"x":6,"y":6,"value":1},{"x":7,"y":6,"value":1},{"x":8,"y":6,"value":1},{"x":0,"y":7,"value":0},{"x":1,"y":7,"value":0},{"x":2,"y":7,"value":0},{"x":3,"y":7,"value":0},{"x":4,"y":7,"value":0},{"x":5,"y":7,"value":0},{"x":6,"y":7,"value":1},{"x":7,"y":7,"value":1},{"x":8,"y":7,"value":1},{"x":0,"y":8,"value":0},{"x":1,"y":8,"value":0},{"x":2,"y":8,"value":0},{"x":3,"y":8,"value":0},{"x":4,"y":8,"value":0},{"x":5,"y":8,"value":0},{"x":6,"y":8,"value":1},{"x":7,"y":8,"value":1},{"x":8,"y":8,"value":1}]}]} \ No newline at end of file From 564f01f70ac4a4e55951cc23b9e13b87a2f105d1 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 14:32:44 +0100 Subject: [PATCH 11/21] =?UTF-8?q?Farbe=20von=20Buttons=20ge=C3=A4ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/src/TasksFrame.java | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 0c367fd..b2de3c1 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -7,6 +7,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.LinkedList; +import java.awt.Color; public class TasksFrame extends JFrame { @@ -90,6 +91,8 @@ public class TasksFrame extends JFrame { JButton button = new JButton("round sum"); button.setVisible(true); button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); @@ -150,6 +153,8 @@ public class TasksFrame extends JFrame { JButton button = new JButton("kgV"); button.setVisible(true); button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); @@ -195,6 +200,8 @@ public class TasksFrame extends JFrame { JButton button = new JButton("Quersumme"); button.setVisible(true); button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); JTextField jTextField = new JTextField(); jTextField.setVisible(true); @@ -240,6 +247,8 @@ public class TasksFrame extends JFrame { JButton button = new JButton("calc Phi"); button.setVisible(true); button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); JTextField jTextField = new JTextField(); jTextField.setVisible(true); @@ -301,9 +310,11 @@ public class TasksFrame extends JFrame { jLabel.setBounds(20, 80, 150, 30); jLabel.setVisible(true); - Button button = new Button("Say Hello World"); + JButton button = new JButton("Say Hello World"); button.setBounds(10, 50, 150, 30); button.setVisible(true); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -345,6 +356,8 @@ public class TasksFrame extends JFrame { JButton add = new JButton("add"); add.setBounds(10, 90, 100, 30); add.setVisible(true); + add.setForeground(Color.WHITE); + add.setBackground(Color.BLUE); add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -400,6 +413,8 @@ public class TasksFrame extends JFrame { JButton difference = new JButton("Difference"); difference.setBounds(10,90,100,30); difference.setVisible(true); + difference.setForeground(Color.WHITE); + difference.setBackground(Color.BLUE); difference.addActionListener(new ActionListener() { @Override @@ -451,6 +466,8 @@ public class TasksFrame extends JFrame { JButton area = new JButton("Calculate area"); area.setVisible(true); area.setBounds(0, 80, 180,30); + area.setForeground(Color.WHITE); + area.setBackground(Color.BLUE); JTextField areaRes = new JTextField(); areaRes.setBounds(200,80,30,20 ); @@ -478,6 +495,8 @@ public class TasksFrame extends JFrame { JButton perimeter = new JButton("Calculate perimeter"); perimeter.setVisible(true); perimeter.setBounds(0, 110, 180,30); + perimeter.setForeground(Color.WHITE); + perimeter.setBackground(Color.BLUE); JTextField perimeterRes = new JTextField(); perimeterRes.setBounds(200,110,30,20 ); @@ -532,6 +551,8 @@ public class TasksFrame extends JFrame { JButton sumFromTo = new JButton("calculate"); sumFromTo.setBounds(10,90,100,30); sumFromTo.setVisible(true); + sumFromTo.setForeground(Color.WHITE); + sumFromTo.setBackground(Color.BLUE); sumFromTo.addActionListener(new ActionListener() { @Override From 765893f084fb3fd657c100067a02c0b950ff8b29 Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Thu, 2 Feb 2023 15:19:59 +0100 Subject: [PATCH 12/21] refactorings and it is npos possible to create a new game at sandbox and then load them with the menu bar load new game for all difficulties. its even possible to walk through the games of that difficulty with next button. this button is queuing --- src/main/java/src/GameField.java | 10 ++++- src/main/java/src/MainFrame.java | 66 ++++++++++++++++++++++++++++- src/main/java/src/Model.java | 2 +- src/main/java/src/SandboxFrame.java | 3 +- src/test/java/ModelTest.java | 5 ++- 5 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/main/java/src/GameField.java b/src/main/java/src/GameField.java index 653f516..01e3bea 100644 --- a/src/main/java/src/GameField.java +++ b/src/main/java/src/GameField.java @@ -122,8 +122,14 @@ public class GameField extends JPanel { public void setValue(int x, int y, int value) { JLabel jLabel = gameField[y][x].getjLabel(); - jLabel.setText(String.valueOf(value)); - jLabel.setVisible(true); + + if (value <= 0) { + jLabel.setText("0"); + jLabel.setVisible(false); + } else { + jLabel.setText(String.valueOf(value)); + jLabel.setVisible(true); + } } diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java index f9b2d7c..98378ee 100644 --- a/src/main/java/src/MainFrame.java +++ b/src/main/java/src/MainFrame.java @@ -19,6 +19,8 @@ public class MainFrame extends JFrame { private JSONArray currentGameDifficulty; private Model currentModel; + private JLabel currentGameLabel; + private int currentPosition; public void run() { @@ -79,10 +81,37 @@ public class MainFrame extends JFrame { JButton back = new JButton(); back.setVisible(true); - back.setBounds(5, 5, 100, 25); + back.setBounds(120, 525, 100, 25); rootPanel.add(back); back.setText("Back"); + currentGameLabel = new JLabel(); + currentGameLabel.setVisible(true); + currentGameLabel.setBounds(250, 525, 40, 25); + currentGameLabel.setText("0/0"); + rootPanel.add(currentGameLabel); + + JButton next = new JButton(); + next.setVisible(true); + next.setBounds(280, 525, 100, 25); + rootPanel.add(next); + next.setText("Next"); + next.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + + if (currentPosition+1 < currentGameDifficulty.size()) { + currentPosition++; + } else { + currentPosition = 0; + } + JSONObject jsonObject = (JSONObject) currentGameDifficulty.get(currentPosition); + loadDataToGameField(jsonObject); + + currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + } + }); + JButton newButton = new JButton(); newButton.setVisible(true); newButton.setBounds(395, 5, 100, 25); @@ -206,11 +235,46 @@ public class MainFrame extends JFrame { } currentGameDifficulty = (JSONArray) object.get("easyGame"); loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); + currentPosition = 0; + currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); } }); JMenuItem menu_i5=new JMenuItem("Mittel"); + menu_i5.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String data = Model.loadAllData(); + JSONObject object = null; + try { + object = (JSONObject)new JSONParser().parse(data); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + currentGameDifficulty = (JSONArray) object.get("mediumGame"); + loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); + currentPosition = 0; + currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + } + }); + JMenuItem menu_i6=new JMenuItem("Schwer"); + menu_i6.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String data = Model.loadAllData(); + JSONObject object = null; + try { + object = (JSONObject)new JSONParser().parse(data); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + currentGameDifficulty = (JSONArray) object.get("hardGame"); + loadDataToGameField((JSONObject) currentGameDifficulty.get(0)); + currentPosition = 0; + currentGameLabel.setText((currentPosition+1)+"/"+currentGameDifficulty.size()); + } + }); m_menu.add(menu_i1); m_menu.add(menu_i2); diff --git a/src/main/java/src/Model.java b/src/main/java/src/Model.java index 66c659a..0cd35fb 100644 --- a/src/main/java/src/Model.java +++ b/src/main/java/src/Model.java @@ -207,7 +207,7 @@ public class Model { JSONObject jsonObject = new JSONObject(); jsonObject.put("x", j); jsonObject.put("y", i); - jsonObject.put("value", getField(i, j)); + jsonObject.put("value", getField(j, i)); values.add(jsonObject); } diff --git a/src/main/java/src/SandboxFrame.java b/src/main/java/src/SandboxFrame.java index 4fffa86..5a9ded2 100644 --- a/src/main/java/src/SandboxFrame.java +++ b/src/main/java/src/SandboxFrame.java @@ -23,7 +23,6 @@ public class SandboxFrame extends JFrame { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setupLayout(); - } private void setupLayout() { @@ -58,6 +57,7 @@ public class SandboxFrame extends JFrame { } private JButton setupSaveButton() { + JButton save = new JButton("Save"); save.setVisible(true); @@ -72,6 +72,7 @@ public class SandboxFrame extends JFrame { } }); + return save; } diff --git a/src/test/java/ModelTest.java b/src/test/java/ModelTest.java index b8fe6ba..f4af955 100644 --- a/src/test/java/ModelTest.java +++ b/src/test/java/ModelTest.java @@ -46,6 +46,7 @@ public class ModelTest extends MainFrame { "8 | 8 8 8 8 8 8 8 8 8\n"; + assertEquals(model.toString(), staticCase, "tested Overridden toString of Model.class"); } @@ -247,7 +248,7 @@ public class ModelTest extends MainFrame { GameField gameField = new GameField(360); for (int i = 0, k = 13; i < 9; i++) { for (int j = 0, l = 17; j < 9; j++) { - gameField.setValue(i, j, (i*l+j*k)%9); + gameField.setValue(j, i, (i*l+j*k)%9); } } Model model = new Model(gameField); @@ -273,7 +274,7 @@ public class ModelTest extends MainFrame { GameField gf = new GameField(360); for (int i = 0, k = 13; i < 9; i++) { for (int j = 0, l = 17; j < 9; j++) { - gf.setValue(i, j, (i*l+j*k)%9); + gf.setValue(j, i, (i*l+j*k)%9); } } Model m = new Model(gf); From 0be46f95e63013598e3018a61e02a41fee47834c Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 15:23:48 +0100 Subject: [PATCH 13/21] JTextField font style changed --- src/main/java/src/TasksFrame.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index b2de3c1..6d07a72 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -97,14 +97,17 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); a.setVisible(true); + a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 40, 30, 20); b.setVisible(true); + b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField c = new JTextField(); c.setBounds(90, 40, 30, 20); c.setVisible(true); + c.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -159,10 +162,12 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); a.setVisible(true); + a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 40, 30, 20); b.setVisible(true); + b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -183,6 +188,8 @@ public class TasksFrame extends JFrame { int res = kgV(val_a, val_b); jLabel.setText(String.valueOf(res)); } + + }); @@ -206,6 +213,7 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds(10, 40, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -253,6 +261,9 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds( 10, 40, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + + JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -334,6 +345,7 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 50, 30, 20); a.setVisible(true); + a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel sum = new JLabel(); sum.setBounds(40, 50, 10, 20); @@ -343,6 +355,7 @@ public class TasksFrame extends JFrame { JTextField b = new JTextField(); b.setBounds(50, 50, 30, 20); b.setVisible(true); + b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel equal = new JLabel(); equal.setBounds(90, 50, 30, 20); @@ -352,6 +365,7 @@ public class TasksFrame extends JFrame { JTextField result = new JTextField(); result.setBounds(100, 50, 40, 20); result.setVisible(true); + result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JButton add = new JButton("add"); add.setBounds(10, 90, 100, 30); @@ -391,6 +405,7 @@ public class TasksFrame extends JFrame { JTextField x = new JTextField(); x.setBounds(10,50,30,20); x.setVisible(true); + x.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel diff = new JLabel(); diff.setBounds(40, 50, 10, 20); @@ -400,6 +415,7 @@ public class TasksFrame extends JFrame { JTextField y = new JTextField(); y.setBounds(50,50,30,20); y.setVisible(true); + y.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JLabel equal = new JLabel(); equal.setBounds(90, 50, 30, 20); @@ -409,6 +425,7 @@ public class TasksFrame extends JFrame { JTextField result = new JTextField(); result.setBounds(100,50,40,20); result.setVisible(true); + result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JButton difference = new JButton("Difference"); difference.setBounds(10,90,100,30); @@ -458,10 +475,12 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setVisible(true); a.setBounds(50,25,30,20); + a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField b = new JTextField(); b.setVisible(true); b.setBounds(50,45,30,20); + b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JButton area = new JButton("Calculate area"); area.setVisible(true); @@ -472,6 +491,7 @@ public class TasksFrame extends JFrame { JTextField areaRes = new JTextField(); areaRes.setBounds(200,80,30,20 ); areaRes.setVisible(true); + areaRes.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); area.addActionListener(new ActionListener() { @Override @@ -501,6 +521,7 @@ public class TasksFrame extends JFrame { JTextField perimeterRes = new JTextField(); perimeterRes.setBounds(200,110,30,20 ); perimeterRes.setVisible(true); + perimeterRes.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); perimeter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -539,14 +560,17 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 50, 30, 20); a.setVisible(true); + a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 50, 30, 20); b.setVisible(true); + b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JTextField result = new JTextField(); result.setBounds(100, 50, 40, 20); result.setVisible(true); + result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); JButton sumFromTo = new JButton("calculate"); sumFromTo.setBounds(10,90,100,30); @@ -591,6 +615,7 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds(3, 40, 250, 30); + jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); for (int i = from; i < to; i++) { int e = i % 5; From ada2f09bcebcadfc354e552ec67595aa02be9fe6 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 16:20:36 +0100 Subject: [PATCH 14/21] Font style changed to bold --- src/main/java/src/TasksFrame.java | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 6d07a72..bc5a6ef 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -97,17 +97,17 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); a.setVisible(true); - a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 40, 30, 20); b.setVisible(true); - b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField c = new JTextField(); c.setBounds(90, 40, 30, 20); c.setVisible(true); - c.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + c.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -162,12 +162,12 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 40, 30, 20); a.setVisible(true); - a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 40, 30, 20); b.setVisible(true); - b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -213,7 +213,7 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds(10, 40, 30, 20); - jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel jLabel = new JLabel(); jLabel.setVisible(true); @@ -261,7 +261,7 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds( 10, 40, 30, 20); - jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); @@ -345,7 +345,7 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 50, 30, 20); a.setVisible(true); - a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel sum = new JLabel(); sum.setBounds(40, 50, 10, 20); @@ -355,7 +355,7 @@ public class TasksFrame extends JFrame { JTextField b = new JTextField(); b.setBounds(50, 50, 30, 20); b.setVisible(true); - b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel equal = new JLabel(); equal.setBounds(90, 50, 30, 20); @@ -365,7 +365,7 @@ public class TasksFrame extends JFrame { JTextField result = new JTextField(); result.setBounds(100, 50, 40, 20); result.setVisible(true); - result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + result.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JButton add = new JButton("add"); add.setBounds(10, 90, 100, 30); @@ -405,7 +405,7 @@ public class TasksFrame extends JFrame { JTextField x = new JTextField(); x.setBounds(10,50,30,20); x.setVisible(true); - x.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + x.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel diff = new JLabel(); diff.setBounds(40, 50, 10, 20); @@ -415,7 +415,7 @@ public class TasksFrame extends JFrame { JTextField y = new JTextField(); y.setBounds(50,50,30,20); y.setVisible(true); - y.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + y.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JLabel equal = new JLabel(); equal.setBounds(90, 50, 30, 20); @@ -425,7 +425,7 @@ public class TasksFrame extends JFrame { JTextField result = new JTextField(); result.setBounds(100,50,40,20); result.setVisible(true); - result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + result.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JButton difference = new JButton("Difference"); difference.setBounds(10,90,100,30); @@ -475,12 +475,12 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setVisible(true); a.setBounds(50,25,30,20); - a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField b = new JTextField(); b.setVisible(true); b.setBounds(50,45,30,20); - b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JButton area = new JButton("Calculate area"); area.setVisible(true); @@ -491,7 +491,7 @@ public class TasksFrame extends JFrame { JTextField areaRes = new JTextField(); areaRes.setBounds(200,80,30,20 ); areaRes.setVisible(true); - areaRes.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + areaRes.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); area.addActionListener(new ActionListener() { @Override @@ -521,7 +521,7 @@ public class TasksFrame extends JFrame { JTextField perimeterRes = new JTextField(); perimeterRes.setBounds(200,110,30,20 ); perimeterRes.setVisible(true); - perimeterRes.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + perimeterRes.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); perimeter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -560,17 +560,17 @@ public class TasksFrame extends JFrame { JTextField a = new JTextField(); a.setBounds(10, 50, 30, 20); a.setVisible(true); - a.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField b = new JTextField(); b.setBounds(50, 50, 30, 20); b.setVisible(true); - b.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JTextField result = new JTextField(); result.setBounds(100, 50, 40, 20); result.setVisible(true); - result.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + result.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); JButton sumFromTo = new JButton("calculate"); sumFromTo.setBounds(10,90,100,30); @@ -615,7 +615,7 @@ public class TasksFrame extends JFrame { JTextField jTextField = new JTextField(); jTextField.setVisible(true); jTextField.setBounds(3, 40, 250, 30); - jTextField.setFont(new java.awt.Font("Arial", Font.ROMAN_BASELINE | Font.BOLD, 12)); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); for (int i = from; i < to; i++) { int e = i % 5; From 52b884d4b696bc6ba51227b645ca755a4bebddca Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 16:42:58 +0100 Subject: [PATCH 15/21] =?UTF-8?q?new=20Task=20"Dezimal=20nach=20bin=C3=A4r?= =?UTF-8?q?"=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/src/TasksFrame.java | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index bc5a6ef..81637c2 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -82,9 +82,61 @@ public class TasksFrame extends JFrame { setupKgV(); setupRoundSum(); + setupUmrechnen(); } + private void setupUmrechnen() { + + JPanel jPanel = setupPanel("Dezimal nach Binär"); + + JButton button = new JButton("calculate"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); + + JTextField jTextField = new JTextField(); + jTextField.setVisible(true); + jTextField.setBounds( 10, 40, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10, 90, 60, 30); + + + jPanel.add(button); + jPanel.add(jTextField); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = jTextField.getText(); + Integer val = Integer.valueOf(text); + int res = Integer.valueOf(umrechnen(val)); + jLabel.setText(String.valueOf(res)); + } + }); + } + + public String umrechnen(int dez) { + String binaer = ""; + while (dez > 0) { + if (dez % 2 == 0) { + binaer = "0" + binaer; + } + if (dez % 2 == 1) { + binaer = "1" + binaer; + } + dez = dez / 2; + } + return binaer; + } + private void setupRoundSum() { JPanel jPanel = setupPanel("Runde Summe"); From e70d6ccfd26707132506c150d8f27bb9ce5e5c72 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 16:49:43 +0100 Subject: [PATCH 16/21] =?UTF-8?q?Test=20"Dezimal=20nach=20bin=C3=A4r"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 4af998f..ff2a433 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -147,6 +147,17 @@ class TasksFrameTest { int c = tasksFrame.round10(12); assertEquals(10, c); } + + @Test + void test_umrechnen(){ + TasksFrame tasksFrame = new TasksFrame(); + int a = Integer.parseInt(tasksFrame.umrechnen(15)); + assertEquals(1111, a); + int b = Integer.parseInt(tasksFrame.umrechnen(20)); + assertEquals(10100, b); + int c = Integer.parseInt(tasksFrame.umrechnen(48)); + assertEquals(110000, c); + } } From 9c86b741e4b3aed5c4b0dacec87d2d160e482ea6 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 01:19:33 +0100 Subject: [PATCH 17/21] New task "BMI" added --- src/main/java/src/TasksFrame.java | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 81637c2..a9c7611 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -9,6 +9,8 @@ import java.util.ArrayList; import java.util.LinkedList; import java.awt.Color; +import static java.lang.Double.valueOf; + public class TasksFrame extends JFrame { private final JScrollPane jScrollPane; @@ -81,11 +83,75 @@ public class TasksFrame extends JFrame { setupQuersumme(); setupKgV(); + setupRoundSum(); + setupUmrechnen(); + setupBmi(); + + } + private void setupBmi() { + + JPanel jPanel = setupPanel("BMI Calculator"); + JButton button = new JButton("BMI"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); + + JLabel height = new JLabel("Height/m"); + height.setVisible(true); + height.setBounds(10, 20, 60, 30); + + JTextField jTextField = new JTextField(); + jTextField.setVisible(true); + jTextField.setBounds( 10, 45, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + + JLabel weight = new JLabel("Weight/kg"); + weight.setVisible(true); + weight.setBounds(80, 20, 60, 30); + + JTextField textField = new JTextField(); + textField.setVisible(true); + textField.setBounds( 80, 45, 30, 20); + textField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10, 90, 60, 30); + + + jPanel.add(button); + jPanel.add(jTextField); + jPanel.add(height); + jPanel.add(weight); + jPanel.add(textField); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = jTextField.getText(); + String text1 = textField.getText(); + double val = Double.valueOf(text); + double val1 = Double.valueOf(text1); + double res = Double.valueOf(bmi(val, val1)); + jLabel.setText(String.valueOf(res)); + } + }); + } + + public double bmi(double height, double weight) { + + return weight / (height * height); + } + + private void setupUmrechnen() { JPanel jPanel = setupPanel("Dezimal nach Binär"); From b028f8100ab3e58dfd13df713bfd7dcc9aa719c8 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 01:38:22 +0100 Subject: [PATCH 18/21] BMI Wert auf Zwei Nachkommastellen abrunden + Test "BMI" --- src/main/java/src/TasksFrame.java | 6 ++++-- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index a9c7611..fddb709 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -147,8 +147,10 @@ public class TasksFrame extends JFrame { } public double bmi(double height, double weight) { - - return weight / (height * height); + double result = 0.0; + result = weight / (height * height); + double roundOff = Math.round(result * 100.0) / 100.0; + return roundOff; } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ff2a433..26872fc 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -158,6 +158,17 @@ class TasksFrameTest { int c = Integer.parseInt(tasksFrame.umrechnen(48)); assertEquals(110000, c); } + + @Test + void test_bmi(){ + TasksFrame tasksFrame = new TasksFrame(); + double a = tasksFrame.bmi(1.65, 60.0); + assertEquals(22.04, a); + double b = tasksFrame.bmi(1.95, 72); + assertEquals(18.93, b); + double c = tasksFrame.bmi(1.24, 30); + assertEquals(19.51, c); + } } From 198c44391d09825fcf3ae947b7816eb593c36c6a Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 12:00:48 +0100 Subject: [PATCH 19/21] New task "Datum" added --- src/main/java/src/TasksFrame.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index fddb709..67b7952 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -1,6 +1,7 @@ package src; import javax.swing.*; +import javax.swing.border.Border; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.ActionEvent; @@ -66,6 +67,8 @@ public class TasksFrame extends JFrame { setupHelloWorld(); + setupDate(); + setupSum(); setupDiff(); @@ -91,6 +94,25 @@ public class TasksFrame extends JFrame { setupBmi(); + + + } + + private void setupDate() { + + JPanel jPanel = setupPanel("Datum"); + + String dateStr = String.format("%ta, %1$te. %1$tb %1$tY - %1$tT", System.currentTimeMillis()); + JLabel label = new JLabel(dateStr); + label.setVisible(true); + label.setBounds(10, 45, 160, 50); + Border border = BorderFactory.createLineBorder(Color.BLUE, 3); + label.setBorder(border); + label.setForeground(Color.BLACK); + + + jPanel.add(label); + } private void setupBmi() { From 74a8e4d17bff7735ad340147155ba9dfe216a664 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 13:02:07 +0100 Subject: [PATCH 20/21] New task "Potenzrechner" added --- src/main/java/src/TasksFrame.java | 63 +++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 67b7952..406a8e9 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -89,6 +89,8 @@ public class TasksFrame extends JFrame { setupRoundSum(); + setupExponent(); + setupUmrechnen(); setupBmi(); @@ -96,6 +98,67 @@ public class TasksFrame extends JFrame { + } + + private void setupExponent() { + + JPanel jPanel = setupPanel("Potenzrechner"); + JButton button = new JButton("calculate"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + button.setForeground(Color.WHITE); + button.setBackground(Color.BLUE); + + JLabel height = new JLabel("basis"); + height.setVisible(true); + height.setBounds(10, 20, 60, 30); + + JTextField jTextField = new JTextField(); + jTextField.setVisible(true); + jTextField.setBounds( 10, 45, 30, 20); + jTextField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + + JLabel weight = new JLabel("exponent"); + weight.setVisible(true); + weight.setBounds(80, 20, 60, 30); + + JTextField textField = new JTextField(); + textField.setVisible(true); + textField.setBounds( 80, 45, 30, 20); + textField.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10, 90, 150, 30); + + + jPanel.add(button); + jPanel.add(jTextField); + jPanel.add(height); + jPanel.add(weight); + jPanel.add(textField); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String text = jTextField.getText(); + String text1 = textField.getText(); + double val = Double.valueOf(text); + double val1 = Double.valueOf(text1); + double res = Double.valueOf(expo(val, val1)); + jLabel.setText(String.valueOf(res)); + } + }); + + + } + + public double expo(double base, double exp) { + + double result = Math.pow(base, exp) ; + return result; } private void setupDate() { From 1006cb79684dd400918e4bcc2f42f3a0632cc6f9 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 13:39:45 +0100 Subject: [PATCH 21/21] Test "Potenzrechner" --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 26872fc..e1b47cc 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -169,6 +169,17 @@ class TasksFrameTest { double c = tasksFrame.bmi(1.24, 30); assertEquals(19.51, c); } + + @Test + void test_expo(){ + TasksFrame tasksFrame = new TasksFrame(); + double a = tasksFrame.expo(2, 3); + assertEquals(8, a); + double b = tasksFrame.expo(15, 3); + assertEquals(3375, b); + double c = tasksFrame.expo(10, 0); + assertEquals(1, c); + } }