added gridUpdate to refrech gameGrid after user press to revalidate

colors of buttons
gui
beratkocak 2024-12-20 14:00:39 +01:00
parent 1e640026f7
commit 6a505ef34d
1 changed files with 18 additions and 4 deletions

View File

@ -14,7 +14,8 @@ import javax.swing.JPanel;
import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain; import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain;
public class GameGUI { public class GameGUI {
private static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data){
public static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data){
JFrame frame = new JFrame(); JFrame frame = new JFrame();
int num = buttons.length; int num = buttons.length;
JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0)); JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0));
@ -40,9 +41,9 @@ public class GameGUI {
MenuGUI.getPath(filepath); MenuGUI.getPath(filepath);
}); });
JButton b1 = new JButton("Zurück"); JButton b1 = new JButton("Zurück");
b1.addActionListener(e -> {backOneStep(madeMoves, buttons, colors,gameGrid);}); b1.addActionListener(e -> {HitoriMain.backOneStep(madeMoves, buttons, colors, gameGrid);});
JButton b2 = new JButton("Zurücksetzen"); JButton b2 = new JButton("Zurücksetzen");
b2.addActionListener(e -> {totalResetButton(buttons, colors, madeMoves, data);}); b2.addActionListener(e -> {HitoriMain.totalResetButton(buttons, colors, madeMoves, data);});
JButton b3 = new JButton("Abgeben"); JButton b3 = new JButton("Abgeben");
String path = filepath[0]; String path = filepath[0];
b3.addActionListener(e -> { b3.addActionListener(e -> {
@ -69,7 +70,7 @@ public class GameGUI {
frame.setSize(600,600); frame.setSize(600,600);
} }
private static void paintButton(JButton b, String[] pos, String[][] colors, Stack<String> madeMoves){ public static void paintButton(JButton b, String[] pos, String[][] colors, Stack<String> madeMoves){
int i = Integer.parseInt(pos[0]); int i = Integer.parseInt(pos[0]);
int j = Integer.parseInt(pos[1]); int j = Integer.parseInt(pos[1]);
String col = colors[Integer.parseInt(pos[0])][Integer.parseInt(pos[1])]; String col = colors[Integer.parseInt(pos[0])][Integer.parseInt(pos[1])];
@ -106,5 +107,18 @@ public class GameGUI {
String logEntrance = i+"."+j+"."+"W"; String logEntrance = i+"."+j+"."+"W";
madeMoves.push(logEntrance); madeMoves.push(logEntrance);
} }
public static void gridUpdate(JPanel grid, JButton[][] buttons){
grid.removeAll();
grid.repaint();
for(int i = 0; i<buttons.length; i++){
for(int j = 0; j<buttons.length;j++){
JButton b0 = buttons[i][j];
grid.add(b0);
grid.repaint();
}
}
}
} }
} }