How to declare chess pieces in a chess game?
<p>Im coding a chess game actually. I made the chessboard with cases and I can get coordinates.</p>

<p>My question is : How can I make (by example) a <em>Pawn</em> class with its attributes (<em>color</em> etc..) for my game.</p>

<p>Thanks everyone!</p>

<p>My code actually is :</p>

<pre><code>    package coordboutons;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class CoordBoutons extends JFrame {

CoordBoutons() {
    super("GridLayout");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container contenant = getContentPane();
    contenant.setLayout(new GridLayout(8, 8));

    for (int i = 0; i &lt; 8; i++) {
        for (int j = 0; j &lt; 8; j++) {
            contenant.add(new CaseEchiquier(i, j));
        }
    }

    pack();
    setVisible(true);
}

class CaseEchiquier extends JPanel {

    private int lin, col;
    private char column;

    CaseEchiquier(int i, int j) {
        lin = i;
        col = j;
        setPreferredSize(new Dimension(80, 75));
        setBackground((i + j) % 2 == 0 ? Color.WHITE : Color.GRAY);
        addMouseListener(new MouseAdapter() {


            @Override
            public void mousePressed(MouseEvent e){
                CaseEchiquier current =(CaseEchiquier)e.getSource(); // get the object that the user pressed
                int linX = current.getLin();
                int colY = current.getCol();
                System.out.println(lin+"   "+col);

            }



        });

    }
    public int getCol() {
        return col;
    }

    public int getLin() {
        return lin;
    }

}

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFrame.setDefaultLookAndFeelDecorated(true);
            CoordBoutons coordBoutons = new CoordBoutons();
        }
    });
}
}
</code></pre>
