too many errors in there to try and commpile to see what's going on,
so this is basically the steps I've used in the past (hopefully haven't missed any)
setup for a 4 x 4 grid of buttons
(JPanel(gridlayout(4,4)) and frame
you should be familiar with)
a) button array[16]
b) imageIcon array[16]
c) class variable to hold index number of 'open' button (1st button of pair attempt)
int buttonShowingIndex = -1;//initial value should be -1
d) create an actionListener (it does all the work), can be an inner class/separate/whatever
for each button (in a loop):
a) create the button
b) set it's name property to the index of the loop
c) give it a preferredSize (optional)
d) add the listener
e) add it to the panel
for the imageIcons:
a) create the 1st 8 only (indexes 0 to 7)
b) set the next 8 linked to the 1st 8 (icon[8] = icon[0], icon[9] = icon[1] etc)
c) imageicon array gets shuffled in a reset() method which is called when game starts or for 'new game'
the actionListener's job:
a) get the source button (srcButton)
b) get it's index number by parsing srcButton.getName() (int srcBtnIndex)
c) set the corresponding imageIcon from the imageIcon array
d) now the nitty gritty:
check if buttonShowingIndex > -1
if false (this will be in the 'else' part) buttonShowingIndex = srcBtnIndex
as this will be the 1st button of a pair attempt
if true:
i) buttonShowingIndex will have the index number of the 1st 'open' button
ii) compare the icons of button[buttonShowingIndex] and button[srcBtnIndex]
and if equal, either do nothing, or remove the listener from each button (the icons will stay)
if not equal, start a swing timer (no repeats) to set both button's icons to null, and to reset
buttonShowingIndex to -1
the reset method:
java.util.Collections.shuffle(java.util.Arrays.asList(icons));//shuffles the array
for(int x = 0, y = buttons.length; x < y; x++) buttons[x].setIcon(null);//sets them all blank again