I have two files PokerCards and Frame.
PokerCards is enumeration *my suits work fine*
enum Number {
Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King;
public static final Number[] numbers = Number.values();
public static Number getNumber(int n){
return Number.numbers[n];
}
}
private final Number number;
//constructor
public PokerCards(final Suit suit, final Number number){
this.suit = suit;
this.number = number;
}
public Number getNumber(){
return this.number;
}
Below is Frame which is to be my GUI. My error checking for suits work perfectly but my numbers...not so much. I am trying to use an enhanced for-loop to match the corresponding enumeration
//card1Num is the value of the card such as Ace, Three, King and is recorded via a TextField via the GUI.
card1Num = card1TextFieldNum.getText();
if (card1Suit.equalsIgnoreCase("Diamonds")){
for (PokerCards.Number n : PokerCards.Number.values()) { //GETS STUCK
if(n.name().equals(card1Num)) {
card1 = new PokerCards(PokerCards.Suit.Diamonds, PokerCards.Number.valueOf(card1Num));
System.out.println("Card 1 good to GO");
card1Good = true;
} else {
JFrame popUpError2 = new JFrame();
JOptionPane.showMessageDialog(popUpError2, "Incorrect Input, Number Input for First Card is incorrect! Please double check" +
" your input", "ERROR", JOptionPane.ERROR_MESSAGE);
break;
}
}
Everything works lovely except the enhanced for-loop. As i test other cards i get prompted by my error. It only accepts 'Ace', the first element. Why is my enhanced for-loop getting stuck?