Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need some help on setting up arrays and charAt
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shadowofanubis66




PostPosted: Wed Dec 05, 2007 7:17 pm   Post subject: Need some help on setting up arrays and charAt

I'm having some issue with making a matching card game. Our teacher wants us to have 2 parallel arrays, one for names and one for the buttons. I've set those up, but the problem is, i dont know how to get "random" letters and numbers from the names array. I dont want all 2c like i'm getting with the code below. After i figure that out, 2c would then be 2c.gif and then show the picture 2c.gif on one of the buttons. Could anyone help me out in figuring that out? My code that i currently have is below. Thanks in advance... I appreciate any help you can give.

public void setupButtons(){
buttons = new JButton[16];
Icon icon = new ImageIcon("icon.gif");
for (i=0; i < 16; i++){
buttons[i] = new JButton(names[i]);
buttons[i].setName(names[i]);
buttons[i].addActionListener(this);
add(buttons[i]);
}
}

public void initGame(){
setupName();
setupButtons();
}

public void setupName(){

names = new String[16];
for (i=0; i < 16; i++){

names[i] = "" + "23456789tjqka".charAt(value) + "cdhs".charAt(suit);
}
shuffle(names);
}
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: Wed Dec 05, 2007 7:46 pm   Post subject: RE:Need some help on setting up arrays and charAt

use the Random class? I dont get what you are trying to do here, but
"23456789tjqka".charAt(value) + "cdhs".charAt(suit)
value and suit never changes value, that is probably why? so stick a random variable somewhere in that loop and you'll be good
Euphoracle




PostPosted: Wed Dec 05, 2007 7:52 pm   Post subject: RE:Need some help on setting up arrays and charAt

Get a random byte between x and y, then cast it to char. Be sure your range (x & y) is within the ASCII "numbers" for a-Z (notice lower->capital). x <= a; y >= Z.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: