import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ApplicationWindow {
private JFrame frame=null;
private JPanel panel=null;
private Square[][] square;
private int FIELDROW = 7;
private int FIELDCOLUMN =6;
private boolean forPicture = true;
private final String projPath = System.getProperty("user.dir");
private final String imagesPath = "/src/tud/project/gameWindowPictures/";
private final String pathGreen = projPath + imagesPath + "green.jpg";
private final String pathLGreen = projPath + imagesPath + "lgreen.jpg";
private ImageIcon iILGreen=new ImageIcon(pathLGreen);
private ImageIcon iIGreen=new ImageIcon(pathGreen);
public void initializePanel(){
panel = new JPanel();
panel.setVisible(true);
panel.setLayout(new GridLayout(FIELDCOLUMN, FIELDROW,0,0));
panel.setBorder(BorderFactory.createEmptyBorder());
for (int i=0;i < FIELDCOLUMN;i++)
for (int k=0;k < FIELDROW;k++)
panel.add(square[i][k]);
}
public void initializeSquare(){
square = new Square[FIELDCOLUMN][FIELDROW];
for (int i=0;i< FIELDCOLUMN;i++){
for (int k=0;k<FIELDROW;k++){
if (forPicture){
square[i][k] = new Square(i,k,iILGreen);
forPicture = !forPicture;
}
else{
square[i][k] = new Square(i,k,iIGreen);
forPicture = !forPicture;
}
}
}
}
public void initializeFrame(){
frame = new JFrame("GameWindow");
frame.setBounds(100, 100, 500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
}
public void showGUI() {
frame.setVisible(true);
}
public ApplicationWindow (){
initializeSquare();
initializePanel();
initializeFrame();
}
public static void main (String[] args){
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
ApplicationWindow window1 = new ApplicationWindow();
window1.showGUI();
}
});
}
}