我想使用String数组中的值来命名JButton
。
我正在制作 UNO游戏,并想制作一堆JButtons
。每个JButton对应一个ImageIcon
,它是一张卡。
Stack<JButton> deck = new Stack<JButton>();
String[] cards = new String[25];
//Make a string array of cards
for (int i = 0; i < 25; i++){
cards[i] = suits + values[i%25];
}
//Make a deck of card buttons
for (int i = 0; i < 25; i++){
String cardName = cards[i];
ImageIcon cardIcon = new ImageIcon(cardName);
JButton cardButton = new JButton();
cardButton.setIcon(cardIcon);
deck.push(cardButton);
}