
import javax.swing.*;
import java.awt.*;

public class ChessBoard 
{

	JFrame frame;
	JPanel squares[][] = new JPanel[8][8];
	
	public ChessBoard() 
	{
				
		frame = new JFrame("Bil113 Satranç");
	    frame.setSize(550, 550);
	    frame.setLayout(new GridLayout(8, 8));
	    
	    
	    for (int i = 0; i < 8; i++) {
	    	for (int j = 0; j < 8; j++) {
	
	            squares[i][j] = new JPanel();
	
	            if ((i + j) % 2 == 0) {
	                squares[i][j].setBackground(Color.white);
	            } else {
	                squares[i][j].setBackground(Color.lightGray);
	            }   
	            frame.add(squares[i][j]);
	        }
	    }
	    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    frame.setVisible(true);	    
	}
	
	public void removeIcon(int x,int y,String s,char c)
	{
		switch (c)
		{
		case 'b':
			if (s.equals("piyon"))
				squares[x][y].removeAll();
			else if (s.equals("kale"))
				squares[x][y].removeAll();
			else if (s.equals("at"))
				squares[x][y].removeAll();
			else if (s.equals("fil"))
				squares[x][y].removeAll();
			else if (s.equals("vezir"))
				squares[x][y].removeAll();
			else if (s.equals("sah"))
				squares[x][y].removeAll();	
			break;
		case 's':
			if (s.equals("piyon"))
				squares[x][y].removeAll();
			else if (s.equals("kale"))
				squares[x][y].removeAll();
			else if (s.equals("at"))
				squares[x][y].removeAll();
			else if (s.equals("fil"))
				squares[x][y].removeAll();
			else if (s.equals("vezir"))
				squares[x][y].removeAll();
			else if (s.equals("sah"))
				squares[x][y].removeAll();
			break;
		}
		frame.repaint();		
		frame.setVisible(true);
	}
	
	public void putIcon(int x,int y,String s,char c)
	{
		switch (c)
		{
		case 'b':
			if (s.equals("piyon"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-01-Pone-icon.png")));
			else if (s.equals("kale"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-02-Castle-icon.png")));
			else if (s.equals("at"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-03-Knight-icon.png")));
			else if (s.equals("fil"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-04-Bishop-icon.png")));
			else if (s.equals("vezir"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-05-Queen-icon.png")));
			else if (s.equals("sah"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/white-06-King-icon.png")));	
			break;
		case 's':
			if (s.equals("piyon"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-07-Pone-icon.png")));
			else if (s.equals("kale"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-08-Castle-icon.png")));
			else if (s.equals("at"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-09-Knight-icon.png")));
			else if (s.equals("fil"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-10-Bishop-icon.png")));
			else if (s.equals("vezir"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-11-Queen-icon.png")));
			else if (s.equals("sah"))
				squares[x][y].add(new JLabel(new ImageIcon("bin/black-12-King-icon.png")));
			break;
		}
		frame.repaint();	
		frame.setVisible(true);		
	}
}