added paint game method to take input from csv reading method and make a
jframe of buttonsgui
parent
2aaac10f48
commit
cf38b86df1
|
@ -1,5 +1,70 @@
|
||||||
package de.hs_mannheim.informatik.pr2projekt.gui;
|
package de.hs_mannheim.informatik.pr2projekt.gui;
|
||||||
|
|
||||||
public class GameGUI {
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
import de.hs_mannheim.informatik.pr2projekt.domain.HitoriMain;
|
||||||
|
|
||||||
|
public class GameGUI {
|
||||||
|
private static void paintGame(String[] filepath, JButton[][] buttons, String[][] colors, Stack<String> madeMoves, String[][] data){
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
int num = buttons.length;
|
||||||
|
JPanel gameGrid = new JPanel(new GridLayout(num,num,0,0));
|
||||||
|
for(int i=0;i<num;i++){
|
||||||
|
for(int j=0;j<num;j++){
|
||||||
|
JButton b = buttons[i][j];
|
||||||
|
b.setOpaque(true);
|
||||||
|
b.setContentAreaFilled(true);
|
||||||
|
b.setBorderPainted(false);
|
||||||
|
b.setFocusPainted(false);
|
||||||
|
b.setBackground(Color.WHITE);
|
||||||
|
gameGrid.add(b);
|
||||||
|
String[] pos = HitoriMain.getCords(i,j);
|
||||||
|
b.addActionListener(e -> {paintButton(b, pos, colors , madeMoves);});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
|
mainPanel.add(gameGrid, BorderLayout.CENTER);
|
||||||
|
JPanel buttonGrid = new JPanel(new GridLayout(1,4,10,10));
|
||||||
|
JButton b0 = new JButton("Aufgeben");
|
||||||
|
b0.addActionListener(e -> {
|
||||||
|
frame.dispose();
|
||||||
|
MenuGUI.getPath(filepath);
|
||||||
|
});
|
||||||
|
JButton b1 = new JButton("Zurück");
|
||||||
|
b1.addActionListener(e -> {backOneStep(madeMoves, buttons, colors,gameGrid);});
|
||||||
|
JButton b2 = new JButton("Zurücksetzen");
|
||||||
|
b2.addActionListener(e -> {totalResetButton(buttons, colors, madeMoves, data);});
|
||||||
|
JButton b3 = new JButton("Abgeben");
|
||||||
|
String path = filepath[0];
|
||||||
|
b3.addActionListener(e -> {
|
||||||
|
try{
|
||||||
|
boolean levelFinished = HitoriMain.abgabeMöglich(path, data, colors);
|
||||||
|
if(levelFinished == true){
|
||||||
|
HitoriMain.finish(path, data, colors);
|
||||||
|
frame.dispose();
|
||||||
|
} else {
|
||||||
|
JLabel text1 = new JLabel("Abgabe nicht richtig!");
|
||||||
|
mainPanel.add(text1, BorderLayout.NORTH);
|
||||||
|
mainPanel.revalidate();
|
||||||
|
mainPanel.repaint();
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException i) {
|
||||||
|
System.out.println("File not found: " + i.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttonGrid.add(b0);buttonGrid.add(b1);buttonGrid.add(b2);buttonGrid.add(b3);
|
||||||
|
mainPanel.add(buttonGrid, BorderLayout.SOUTH);
|
||||||
|
mainPanel.setVisible(true);
|
||||||
|
frame.add(mainPanel);
|
||||||
|
frame.setVisible(true);
|
||||||
|
frame.setSize(600,600);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue