Fehler beim Laden des Hauptmenüs behoben
parent
078d653921
commit
7139741018
|
@ -33,5 +33,6 @@ public class HitoriSolutionLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
return solutionCoordinates;
|
return solutionCoordinates;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -227,14 +227,19 @@ public class GameBoard extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void returnToMainMenu() {
|
private void returnToMainMenu() {
|
||||||
// Eltern-Frame abrufen
|
/// Eltern-Frame abrufen
|
||||||
JFrame parentFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
|
JFrame parentFrame = (JFrame) SwingUtilities.getWindowAncestor(this);
|
||||||
|
|
||||||
// Inhalt des Frames auf das Hauptmenü setzen
|
if (parentFrame != null) {
|
||||||
parentFrame.getContentPane().removeAll();
|
// Hauptmenü erstellen und im Frame setzen
|
||||||
parentFrame.add(new StartMenu());
|
StartMenu startMenu = new StartMenu(parentFrame);
|
||||||
parentFrame.revalidate();
|
parentFrame.getContentPane().removeAll(); // Entferne alle aktuellen Inhalte
|
||||||
parentFrame.repaint();
|
parentFrame.add(startMenu); // Füge das Hauptmenü hinzu
|
||||||
|
parentFrame.revalidate(); // Layout aktualisieren
|
||||||
|
parentFrame.repaint(); // Oberfläche neu zeichnen
|
||||||
|
} else {
|
||||||
|
System.err.println("Fehler: Kein übergeordnetes JFrame gefunden.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JButton createButton(String text, int width, int height) {
|
private JButton createButton(String text, int width, int height) {
|
||||||
|
|
|
@ -13,15 +13,14 @@ import java.util.Random;
|
||||||
|
|
||||||
import static PR2.HitoriSpiel.GUI.BoardLoader.loadBoard;
|
import static PR2.HitoriSpiel.GUI.BoardLoader.loadBoard;
|
||||||
|
|
||||||
public class StartMenu extends JFrame {
|
public class StartMenu extends JPanel {
|
||||||
private JPanel mainPanel;
|
private final JFrame parentFrame;
|
||||||
|
|
||||||
public StartMenu() {
|
public StartMenu(JFrame parentFrame) {
|
||||||
setTitle("Hitori - Hauptmenü");
|
this.parentFrame = parentFrame;
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setLayout(new GridBagLayout());
|
||||||
setSize(800, 600);
|
|
||||||
|
|
||||||
mainPanel = new JPanel(new GridBagLayout());
|
//mainPanel = new JPanel(new GridBagLayout());
|
||||||
GridBagConstraints gbc = new GridBagConstraints();
|
GridBagConstraints gbc = new GridBagConstraints();
|
||||||
gbc.gridx = 0;
|
gbc.gridx = 0;
|
||||||
gbc.gridy = GridBagConstraints.RELATIVE;
|
gbc.gridy = GridBagConstraints.RELATIVE;
|
||||||
|
@ -31,7 +30,7 @@ public class StartMenu extends JFrame {
|
||||||
JLabel titleLabel = new JLabel("Willkommen im Hitori-Spiel!");
|
JLabel titleLabel = new JLabel("Willkommen im Hitori-Spiel!");
|
||||||
titleLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
titleLabel.setFont(new Font("Arial", Font.BOLD, 16));
|
||||||
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
mainPanel.add(titleLabel, gbc);
|
add(titleLabel, gbc);
|
||||||
|
|
||||||
|
|
||||||
// Buttons erstellen
|
// Buttons erstellen
|
||||||
|
@ -42,11 +41,11 @@ public class StartMenu extends JFrame {
|
||||||
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
||||||
|
|
||||||
|
|
||||||
mainPanel.add(continueButton, gbc);
|
add(continueButton, gbc);
|
||||||
mainPanel.add(selectBoardButton, gbc);
|
add(selectBoardButton, gbc);
|
||||||
mainPanel.add(randomBoardButton, gbc);
|
add(randomBoardButton, gbc);
|
||||||
mainPanel.add(highscorelistButton, gbc);
|
add(highscorelistButton, gbc);
|
||||||
mainPanel.add(exitButton, gbc);
|
add(exitButton, gbc);
|
||||||
|
|
||||||
continueButton.addActionListener(e -> continueGame());
|
continueButton.addActionListener(e -> continueGame());
|
||||||
selectBoardButton.addActionListener(e -> selectBoard());
|
selectBoardButton.addActionListener(e -> selectBoard());
|
||||||
|
@ -54,9 +53,6 @@ public class StartMenu extends JFrame {
|
||||||
highscorelistButton.addActionListener(e -> highscorelist());
|
highscorelistButton.addActionListener(e -> highscorelist());
|
||||||
exitButton.addActionListener(e -> System.exit(0));
|
exitButton.addActionListener(e -> System.exit(0));
|
||||||
|
|
||||||
add(mainPanel);
|
|
||||||
setVisible(true);
|
|
||||||
setLocationRelativeTo(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void continueGame() {
|
private void continueGame() {
|
||||||
|
@ -125,11 +121,11 @@ public class StartMenu extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
private void loadGameBoard(GameBoard gameBoard, List<String> solutionCoordinates) {
|
||||||
mainPanel.removeAll();
|
removeAll();
|
||||||
mainPanel.setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
mainPanel.add(gameBoard, BorderLayout.CENTER);
|
add(gameBoard, BorderLayout.CENTER);
|
||||||
mainPanel.revalidate();
|
revalidate();
|
||||||
mainPanel.repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAndDisplayBoard(String selectedFile) {
|
private void loadAndDisplayBoard(String selectedFile) {
|
||||||
|
@ -154,4 +150,7 @@ public class StartMenu extends JFrame {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,14 +12,15 @@ import javax.swing.*;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
try {
|
JFrame frame = new JFrame("Hitori - Hauptmenü");
|
||||||
new StartMenu();
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
} catch (Exception e) {
|
frame.setSize(800, 600);
|
||||||
e.printStackTrace();
|
frame.setLocationRelativeTo(null);
|
||||||
JOptionPane.showMessageDialog(null, "Ein schwerer Fehler ist aufgetreten: " + e.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
StartMenu startMenu = new StartMenu(frame);
|
||||||
|
frame.add(startMenu);
|
||||||
|
frame.setVisible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue