Browse Source

habe die projekt struktur geändert und main in eine klasse exportiert.

remotes/origin/develop
fdai6499 2 years ago
parent
commit
4806815f7d
  1. 2
      src/main/java/src/GameField.java
  2. 82
      src/main/java/src/Main.java
  3. 85
      src/main/java/src/MainFrame.java
  4. 2
      src/main/java/src/Notes.java
  5. 2
      src/main/java/src/Tests.java
  6. 2
      src/test/java/GameFieldTest.java
  7. 5
      src/test/java/MainTest.java
  8. 1
      src/test/java/NotesTest.java

2
sudokuExample/src/GameField.java → src/main/java/src/GameField.java

@ -1,3 +1,5 @@
package src;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import java.awt.*; import java.awt.*;

82
sudokuExample/src/Main.java → src/main/java/src/Main.java

@ -1,7 +1,7 @@
package src;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.String; import java.lang.String;
public class Main { public class Main {
@ -23,86 +23,14 @@ public class Main {
@Override @Override
public void run() { 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) { // protected static JPanel setupGameField(int widthHeight) {
// //
// int nrOfFields = 9; // int nrOfFields = 9;

85
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);
}
}

2
sudokuExample/src/Notes.java → src/main/java/src/Notes.java

@ -1,3 +1,5 @@
package src;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;

2
sudokuExample/src/Tests.java → src/main/java/src/Tests.java

@ -1,3 +1,5 @@
package src;
public class Tests { public class Tests {
public static void main(String[] args) { public static void main(String[] args) {

2
src/test/java/GameFieldTest.java

@ -1,4 +1,6 @@
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import src.GameField;
import src.Notes;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;

5
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.*; import static org.junit.jupiter.api.Assertions.*;

1
src/test/java/NotesTest.java

@ -1,4 +1,5 @@
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import src.Notes;
import javax.swing.*; import javax.swing.*;

Loading…
Cancel
Save