In the game I create an array called cards containing 9 cards(2 for user, 2 for computer, and five on the table. its texas hold'em). This array is created if the button deal is clicked. The problem I'm having though is I can not use it in later if statements.
Bellow is the code I am talking about.
public void actionPerformed(ActionEvent event) {
String eventName = event.getActionCommand();
if (eventName == "Deal" & Pot == 0) {
String[] cards;
cards = new String[9];
String[] out;
out = new String[52];
out[0] = "2C.jpg";
out[1] = "2D.jpg";
out[2] = "2H.jpg";
out[3] = "2S.jpg";
out[4] = "3C.jpg";
out[5] = "3D.jpg";
out[6] = "3H.jpg";
out[7] = "3S.jpg";
out[8] = "4C.jpg";
out[9] = "4D.jpg";
out[10] = "4H.jpg";
out[11] = "4S.jpg";
out[12] = "5C.jpg";
out[13] = "5D.jpg";
out[14] = "5H.jpg";
out[15] = "5S.jpg";
out[16] = "6C.jpg";
out[17] = "6D.jpg";
out[18] = "6H.jpg";
out[19] = "6S.jpg";
out[20] = "7C.jpg";
out[21] = "7D.jpg";
out[22] = "7H.jpg";
out[23] = "7S.jpg";
out[24] = "8C.jpg";
out[25] = "8D.jpg";
out[26] = "8H.jpg";
out[27] = "8S.jpg";
out[28] = "9C.jpg";
out[29] = "9D.jpg";
out[30] = "9H.jpg";
out[31] = "9S.jpg";
out[32] = "10C.jpg";
out[33] = "10D.jpg";
out[34] = "10H.jpg";
out[35] = "10S.jpg";
out[36] = "jackC.jpg";
out[37] = "jackD.jpg";
out[38] = "jackH.jpg";
out[39] = "jackS.jpg";
out[40] = "queenC.jpg";
out[41] = "queenD.jpg";
out[42] = "queenH.jpg";
out[43] = "queenS.jpg";
out[44] = "kingC.jpg";
out[45] = "kingD.jpg";
out[46] = "kingH.jpg";
out[47] = "kingS.jpg";
out[48] = "aceC.jpg";
out[49] = "aceD.jpg";
out[50] = "aceH.jpg";
out[51] = "aceS.jpg";
int j = 52;
int x = 0;
int i;
int q;
do {
Random generator = new Random();
int rnd = generator.nextInt(j);
q = rnd;
cards[x] = out[q];
x++;
i = 1;
do {
out[q] = out[q + i];
i++;
} while (q + i < j);
j--;
}while(x < 9);
//Sets the cards images
flpPane.remove(lblCards0);
lblCards0 = new JLabel(cards[0] + " ");
flpPane.add(lblCards0);
flpPane.remove(lblCards1);
lblCards1 = new JLabel(cards[1] + " ");
flpPane.add(lblCards1);
flpPane.remove(lblCards2);
lblCards2 = new JLabel(cards[2] + " ");
flpPane.add(lblCards2);
flpPane.remove(lblCards3);
lblCards3 = new JLabel(cards[3] + " ");
flpPane.add(lblCards3);
flpPane.remove(lblCards4);
lblCards4 = new JLabel(cards[4] + " ");
flpPane.add(lblCards4);
contentPane.add(tblPane, BorderLayout.NORTH);
contentPane.add(flpPane, BorderLayout.SOUTH);
contentPane.add(btnPane, BorderLayout.SOUTH);
tblFrame.setContentPane(contentPane);
tblFrame.pack();
} if (eventName == "Match") {
tblPane.remove(lblPot);
Pot = Pot + 5;
lblPot = new JLabel("Pot : " + Pot);
tblPane.add(lblPot);
contentPane.add(tblPane, BorderLayout.NORTH);
contentPane.add(flpPane, BorderLayout.SOUTH);
contentPane.add(btnPane, BorderLayout.SOUTH);
tblFrame.setContentPane(contentPane);
tblFrame.pack();
} if (eventName == "Raise") {
tblPane.remove(lblPot);
Pot = Pot + 10;
lblPot = new JLabel("Pot : " + Pot);
tblPane.add(lblPot);
contentPane.add(tblPane, BorderLayout.NORTH);
contentPane.add(flpPane, BorderLayout.SOUTH);
contentPane.add(btnPane, BorderLayout.SOUTH);
tblFrame.setContentPane(contentPane);
tblFrame.pack();
} if (eventName == "Fold") {
tblPane.remove(lblPot);
Pot = 0;
lblPot = new JLabel("Pot : " + Pot);
tblPane.add(lblPot);
//sets card images blank
flpPane.remove(lblCards0);
lblCards0 = new JLabel(new ImageIcon("img\\cards\\Lay.jpg"));
flpPane.add(lblCards0);
flpPane.remove(lblCards1);
lblCards1 = new JLabel(new ImageIcon("img\\cards\\Lay.jpg"));
flpPane.add(lblCards1);
flpPane.remove(lblCards2);
lblCards2 = new JLabel(new ImageIcon("img\\cards\\Lay.jpg"));
flpPane.add(lblCards2);
flpPane.remove(lblCards3);
lblCards3 = new JLabel(new ImageIcon("img\\cards\\Lay.jpg"));
flpPane.add(lblCards3);
flpPane.remove(lblCards4);
lblCards4 = new JLabel(new ImageIcon("img\\cards\\Lay.jpg"));
flpPane.add(lblCards4);
contentPane.add(tblPane, BorderLayout.NORTH);
contentPane.add(flpPane, BorderLayout.SOUTH);
contentPane.add(btnPane, BorderLayout.SOUTH);
tblFrame.setContentPane(contentPane);
tblFrame.pack();
}
}
I am using the variable turn to count how many betting rounds have gone by. This is used to flip the cards. Bet one then flip three, then bet two flip one, bet three flip one, bet and then a winner is chosen. At the moment I do not have the computer betting though I want to get this working first. I cannot tell the JLabel to change to the string held in the array though.
I would have the JLabel changing to the picture that is labeled by the string in the cards array though I currently do not have the pictures.
If you guys could help me out with being able to access the array I would really appreciate it. Thanks !


Sign In
Create Account


Back to top









