d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Matching Game Help
Add Reply New Topic New Poll
Member
Posts: 538
Joined: Jun 7 2012
Gold: 0.00
Mar 4 2013 08:29am
I am trying to make a matching/memory game where the user selects two buttons with images behind them and if they match them the buttons are shown, but if they get it wrong the buttons are reset.
This is wha tI have so far: http://pastebin.com/xwWQm79S
I have the buttons set up, but I have no idea how to put images behind them.
Please help
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 4 2013 06:35pm
Look into ImageButton or Image.
Member
Posts: 538
Joined: Jun 7 2012
Gold: 0.00
Mar 5 2013 07:50am
private ImageIcon[] ImageArray;

public void setImages() {
for(int i=1;i<19;i++){
ImageArray[i] = new ImageIcon("Pictures/"+i+".jpg");
gameButton[i].setIcon(ImageArray[i]);
}
}

I tried to add this to set images for my buttons, but I keep getting this error:

Exception in thread "main" java.lang.NullPointerException
at MatchingGame.setImages(MatchingGame.java:65)
at MatchingGame.<init>(MatchingGame.java:26)
at MatchingGame.main(MatchingGame.java:89)


Can someone please help me?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Mar 5 2013 11:48am
initialize ImageArray and gameButton
Member
Posts: 538
Joined: Jun 7 2012
Gold: 0.00
Mar 5 2013 12:59pm
Quote (carteblanche @ Mar 5 2013 01:48pm)
initialize ImageArray and gameButton


What do you mean?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Mar 5 2013 08:29pm
Quote (nubshat @ Mar 5 2013 01:59pm)
What do you mean?


Code
private ImageIcon[] ImageArray;


explain what you think this line does.

edit: actually f that too lazy to wait for response

maybe:

Code
private ImageIcon[] ImageArray = new ImageIcon[36]; //no longer just a reference, now you have successfully put this shit into the heap! congrats!


edit: I guess since it is matching you wouldn't need 36 elements...but you get the idea

This post was edited by Eep on Mar 5 2013 08:33pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll