added paint button to color the buttons after user press
parent
cf38b86df1
commit
1e640026f7
|
|
@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
|
|
@ -67,4 +68,43 @@ public class GameGUI {
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.setSize(600,600);
|
frame.setSize(600,600);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void paintButton(JButton b, String[] pos, String[][] colors, Stack<String> madeMoves){
|
||||||
|
int i = Integer.parseInt(pos[0]);
|
||||||
|
int j = Integer.parseInt(pos[1]);
|
||||||
|
String col = colors[Integer.parseInt(pos[0])][Integer.parseInt(pos[1])];
|
||||||
|
if(col.endsWith("W")){
|
||||||
|
b.setOpaque(true);
|
||||||
|
b.setForeground(Color.BLACK);
|
||||||
|
b.setContentAreaFilled(true);
|
||||||
|
b.setBorderPainted(false);
|
||||||
|
b.setFocusPainted(false);
|
||||||
|
b.setBackground(Color.lightGray);
|
||||||
|
colors[i][j] += "G";
|
||||||
|
String logEntrance = i+"."+j+"."+"G";
|
||||||
|
madeMoves.push(logEntrance);
|
||||||
|
}
|
||||||
|
if(col.endsWith("G")){
|
||||||
|
b.setOpaque(true);
|
||||||
|
b.setForeground(Color.WHITE);
|
||||||
|
b.setContentAreaFilled(true);
|
||||||
|
b.setBorderPainted(false);
|
||||||
|
b.setFocusPainted(false);
|
||||||
|
b.setBackground(Color.BLACK);
|
||||||
|
colors[i][j] += "B";
|
||||||
|
String logEntrance = i+"."+j+"."+"B";
|
||||||
|
madeMoves.push(logEntrance);
|
||||||
|
}
|
||||||
|
if(col.endsWith("B")){
|
||||||
|
b.setOpaque(true);
|
||||||
|
b.setForeground(Color.BLACK);
|
||||||
|
b.setContentAreaFilled(true);
|
||||||
|
b.setBorderPainted(false);
|
||||||
|
b.setFocusPainted(false);
|
||||||
|
b.setBackground(Color.WHITE);
|
||||||
|
colors[i][j] += "W";
|
||||||
|
String logEntrance = i+"."+j+"."+"W";
|
||||||
|
madeMoves.push(logEntrance);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue