One method could be to have a grid of JButton objects. You could have say a two dimensional array of JButtons and then when a user clicks on the JButton, the appropriate image/icon of either the ship or nothing eg a hole in the water appears.
To make these images appear you will need to know something about ActionListeners and also Image creation/manipulation
http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html
is a good starting place.
To create a two dimensional array of JButtons you could do something like this
-
JButton[][] battleshipgrid = new JButton[10][10];
-
for(int i=0; i < battleshipgrid.length; i++) {
-
for(int j=0; j < battleshipgrid.length; j++) {
-
// create new button with a label. Can use an Icon here too.
-
battleshipgrid[i][j] = new JButton("My Button"));
-
}
-
}
-