From 4806815f7d893cfc26656cb724989bdc3743d6cd Mon Sep 17 00:00:00 2001 From: fdai6499 Date: Tue, 10 Jan 2023 21:49:18 +0100 Subject: [PATCH] =?UTF-8?q?habe=20die=20projekt=20struktur=20ge=C3=A4ndert?= =?UTF-8?q?=20und=20main=20in=20eine=20klasse=20exportiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java}/src/GameField.java | 2 + .../main/java}/src/Main.java | 82 ++---------------- src/main/java/src/MainFrame.java | 85 +++++++++++++++++++ .../main/java}/src/Notes.java | 2 + .../main/java}/src/Tests.java | 2 + src/test/java/GameFieldTest.java | 2 + src/test/java/MainTest.java | 5 +- src/test/java/NotesTest.java | 1 + 8 files changed, 101 insertions(+), 80 deletions(-) rename {sudokuExample => src/main/java}/src/GameField.java (99%) rename {sudokuExample => src/main/java}/src/Main.java (53%) create mode 100644 src/main/java/src/MainFrame.java rename {sudokuExample => src/main/java}/src/Notes.java (99%) rename {sudokuExample => src/main/java}/src/Tests.java (97%) diff --git a/sudokuExample/src/GameField.java b/src/main/java/src/GameField.java similarity index 99% rename from sudokuExample/src/GameField.java rename to src/main/java/src/GameField.java index f57aebe..0693441 100644 --- a/sudokuExample/src/GameField.java +++ b/src/main/java/src/GameField.java @@ -1,3 +1,5 @@ +package src; + import javax.swing.*; import javax.swing.border.LineBorder; import java.awt.*; diff --git a/sudokuExample/src/Main.java b/src/main/java/src/Main.java similarity index 53% rename from sudokuExample/src/Main.java rename to src/main/java/src/Main.java index 752183a..b595f61 100644 --- a/sudokuExample/src/Main.java +++ b/src/main/java/src/Main.java @@ -1,7 +1,7 @@ +package src; + import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.lang.String; public class Main { @@ -23,86 +23,14 @@ public class Main { @Override public void run() { - JFrame main = new JFrame(); - main.setLayout(null); - main.setVisible(true); - main.setBounds(300, 200, 500, 600); - main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - JPanel rootPanel = new JPanel(); - rootPanel.setVisible(true); - rootPanel.setBounds(0, 0, 500, 500); - rootPanel.setBackground(Color.LIGHT_GRAY); - rootPanel.setLayout(null); - - GameField gameField = new GameField(360); - gameField.setBounds(70, 50, 360, 360); - rootPanel.add(gameField); - - main.setContentPane(rootPanel); - - JPanel numberPanel = new JPanel(); - numberPanel.setVisible(true); - numberPanel.setBounds(100, 450, 300, 30); - rootPanel.add(numberPanel); - - for (int i = 1, j=0; i < 10; i++) { - JLabel numberi= new JLabel(); - numberi.setText(""+i); - numberi.setBounds(5+j, 5, 20, 20); - numberPanel.setLayout(null); - - JPanel ni = new JPanel(); - ni.setBounds(5+j, 5, 20, 20); - ni.setVisible(true); - ni.setBackground(Color.pink); - ni.add(numberi); - numberPanel.add(ni); - j=j+25; - } - - JLabel number10= new JLabel(); - number10.setText(" "); - number10.setBounds(250, 5, 20, 20); - numberPanel.setLayout(null); - - JPanel n10 = new JPanel(); - n10.setBounds(250, 5, 20, 20); - n10.setVisible(true); - n10.setBackground(Color.pink); - n10.add(number10); - numberPanel.add(n10); - - - - JButton back = new JButton(); - back.setVisible(true); - back.setBounds(5, 5, 100, 25); - rootPanel.add(back); - back.setText("Back"); - - JButton newButton = new JButton(); - newButton.setVisible(true); - newButton.setBounds(395, 5, 100, 25); - newButton.setText("New"); - rootPanel.add(newButton); - - JButton retryButton = new JButton(); - retryButton.setVisible(true); - retryButton.setText("Retry"); - retryButton.setBounds(5, 525, 100, 25); - rootPanel.add(retryButton); - - JButton correctButton = new JButton(); - correctButton.setVisible(true); - correctButton.setText("Correct"); - correctButton.setBounds(395, 525, 100, 25); - rootPanel.add(correctButton); + MainFrame mainFrame = new MainFrame(); + mainFrame.run(); } }); } + // protected static JPanel setupGameField(int widthHeight) { // // int nrOfFields = 9; diff --git a/src/main/java/src/MainFrame.java b/src/main/java/src/MainFrame.java new file mode 100644 index 0000000..a182970 --- /dev/null +++ b/src/main/java/src/MainFrame.java @@ -0,0 +1,85 @@ +package src; + +import javax.swing.*; +import java.awt.*; + +public class MainFrame extends JFrame { + + public void run() { + + this.setLayout(null); + this.setVisible(true); + this.setBounds(300, 200, 500, 600); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + JPanel rootPanel = new JPanel(); + rootPanel.setVisible(true); + rootPanel.setBounds(0, 0, 500, 500); + rootPanel.setBackground(Color.LIGHT_GRAY); + rootPanel.setLayout(null); + + GameField gameField = new GameField(360); + gameField.setBounds(70, 50, 360, 360); + rootPanel.add(gameField); + + this.setContentPane(rootPanel); + + JPanel numberPanel = new JPanel(); + numberPanel.setVisible(true); + numberPanel.setBounds(100, 450, 300, 30); + rootPanel.add(numberPanel); + + for (int i = 1, j=0; i < 10; i++) { + JLabel numberi= new JLabel(); + numberi.setText(""+i); + numberi.setBounds(5+j, 5, 20, 20); + numberPanel.setLayout(null); + + JPanel ni = new JPanel(); + ni.setBounds(5+j, 5, 20, 20); + ni.setVisible(true); + ni.setBackground(Color.pink); + ni.add(numberi); + numberPanel.add(ni); + j=j+25; + } + + JLabel number10= new JLabel(); + number10.setText(" "); + number10.setBounds(250, 5, 20, 20); + numberPanel.setLayout(null); + + JPanel n10 = new JPanel(); + n10.setBounds(250, 5, 20, 20); + n10.setVisible(true); + n10.setBackground(Color.pink); + n10.add(number10); + numberPanel.add(n10); + + + + JButton back = new JButton(); + back.setVisible(true); + back.setBounds(5, 5, 100, 25); + rootPanel.add(back); + back.setText("Back"); + + JButton newButton = new JButton(); + newButton.setVisible(true); + newButton.setBounds(395, 5, 100, 25); + newButton.setText("New"); + rootPanel.add(newButton); + + JButton retryButton = new JButton(); + retryButton.setVisible(true); + retryButton.setText("Retry"); + retryButton.setBounds(5, 525, 100, 25); + rootPanel.add(retryButton); + + JButton correctButton = new JButton(); + correctButton.setVisible(true); + correctButton.setText("Correct"); + correctButton.setBounds(395, 525, 100, 25); + rootPanel.add(correctButton); + } +} diff --git a/sudokuExample/src/Notes.java b/src/main/java/src/Notes.java similarity index 99% rename from sudokuExample/src/Notes.java rename to src/main/java/src/Notes.java index 8faab85..f9b8102 100644 --- a/sudokuExample/src/Notes.java +++ b/src/main/java/src/Notes.java @@ -1,3 +1,5 @@ +package src; + import javax.swing.*; import java.awt.*; diff --git a/sudokuExample/src/Tests.java b/src/main/java/src/Tests.java similarity index 97% rename from sudokuExample/src/Tests.java rename to src/main/java/src/Tests.java index bc22bd3..2cb9b9b 100644 --- a/sudokuExample/src/Tests.java +++ b/src/main/java/src/Tests.java @@ -1,3 +1,5 @@ +package src; + public class Tests { public static void main(String[] args) { diff --git a/src/test/java/GameFieldTest.java b/src/test/java/GameFieldTest.java index fb6b74a..e377591 100644 --- a/src/test/java/GameFieldTest.java +++ b/src/test/java/GameFieldTest.java @@ -1,4 +1,6 @@ import org.junit.jupiter.api.Test; +import src.GameField; +import src.Notes; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java index 6f2536e..40290b8 100644 --- a/src/test/java/MainTest.java +++ b/src/test/java/MainTest.java @@ -1,6 +1,5 @@ -import org.junit.Test; - -import javax.swing.*; +import src.GameField; +import src.Main; import static org.junit.jupiter.api.Assertions.*; diff --git a/src/test/java/NotesTest.java b/src/test/java/NotesTest.java index 9f38fac..18a4e27 100644 --- a/src/test/java/NotesTest.java +++ b/src/test/java/NotesTest.java @@ -1,4 +1,5 @@ import org.junit.jupiter.api.Test; +import src.Notes; import javax.swing.*;