selectedBoard Methode erweitert
parent
6515ea54c4
commit
dd778e7841
|
@ -1,7 +1,6 @@
|
|||
package GUI;
|
||||
package PR2.HitoriSpiel.GUI;
|
||||
|
||||
import domain.HitoriBoard;
|
||||
import persistent.BoardLoader;
|
||||
import PR2.HitoriSpiel.Domain.HitoriBoard;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -15,7 +14,7 @@ public class StartMenu extends JFrame {
|
|||
public StartMenu() {
|
||||
setTitle("Hitori - Hauptmenü");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(600, 400);
|
||||
setSize(800, 600);
|
||||
|
||||
mainPanel = new JPanel(new GridBagLayout());
|
||||
GridBagConstraints gbc = new GridBagConstraints();
|
||||
|
@ -62,23 +61,21 @@ public class StartMenu extends JFrame {
|
|||
|
||||
private void selectBoard() {
|
||||
|
||||
// Lade die Liste der Spielfeld-Dateien
|
||||
List<String> boardFileNames = BoardLoader.loadBoardsAsList();
|
||||
System.out.println("Verfügbare Spielfelder: " + boardFileNames);
|
||||
|
||||
if (boardFileNames.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(this, "Keine Spielfelder gefunden.", "Information", JOptionPane.INFORMATION_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
// Erstelle die JComboBox
|
||||
JComboBox<String> boardSelector = new JComboBox<>(boardFileNames.toArray(new String[0]));
|
||||
boardSelector.setPreferredSize(new Dimension(250, 30)); // Größe der ComboBox anpassen
|
||||
boardSelector.setPreferredSize(new Dimension(250, 30));
|
||||
|
||||
JPanel selectionPanel = new JPanel(new BorderLayout());
|
||||
selectionPanel.add(new JLabel("Wähle ein Spielfeld:"), BorderLayout.NORTH);
|
||||
selectionPanel.add(boardSelector, BorderLayout.CENTER);
|
||||
|
||||
// Zeige das Auswahlfenster
|
||||
int option = JOptionPane.showConfirmDialog(
|
||||
this,
|
||||
selectionPanel,
|
||||
|
@ -87,23 +84,20 @@ public class StartMenu extends JFrame {
|
|||
JOptionPane.PLAIN_MESSAGE
|
||||
);
|
||||
|
||||
// Aktion, wenn der Benutzer auf OK klickt
|
||||
if (option == JOptionPane.OK_OPTION) {
|
||||
String selectedFile = (String) boardSelector.getSelectedItem();
|
||||
System.out.println("Ausgewählte Datei: " + selectedFile);
|
||||
|
||||
if (selectedFile != null) {
|
||||
try {
|
||||
String resourcePath = "/persistent/Hitori_Spielfelder/" + selectedFile;
|
||||
System.out.println("Lade Datei von Pfad: " + resourcePath);
|
||||
|
||||
InputStream inputStream = BoardLoader.class.getResourceAsStream("/persistent/Hitori_Spielfelder/" + selectedFile);
|
||||
if (inputStream == null) {
|
||||
throw new Exception("Ressourcendatei nicht gefunden: /persistent/Hitori_Spielfelder/" + selectedFile);
|
||||
}
|
||||
// Lade das ausgewählte Spielfeld
|
||||
int[][] boardData = BoardLoader.loadBoard("/persistent/Hitori_Spielfelder/" + selectedFile);
|
||||
int[][] boardData = BoardLoader.loadBoard(resourcePath);
|
||||
loadGameBoard(boardData);
|
||||
|
||||
|
||||
|
||||
loadGameBoard(boardData); // Zeige das Spielfeld an
|
||||
} catch (Exception ex) {
|
||||
System.err.println("Fehler beim Laden der Datei: " + ex.getMessage());
|
||||
JOptionPane.showMessageDialog(this, "Fehler beim Laden des Spielfelds: " + ex.getMessage(), "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue