I'm writing a Chinese Chess program in Java and would much appreciate some guidance on designing/implementing the GUI.
The board is to be divided into a 9x10 grid, with an "image" of the chess piece occupying each cell. The cells also need to be 'registered' when clicked so I know which piece was clicked.
1) I'm thinking GridLayout
for the layout manager for the JPanel
representing the board. How do I add an image to each component?
public void paintComponent(Graphics g) {
Image dog = new ImageIcon("dog.png").getImage();
add(dog)
}
Does not work as dog
is not a Component
.
2) How would I register for clicks in each cell?