repeated enabling disabling icon (card flipping)
I'm using a gif icon on a label to display a deck of cards. I have the app to where I can have the shuffled deck either face up or face down and then be
able to drag 5 cards from the top of the deck. If the 5 dragged cards are face
down I can double click on them and they flip face up and if they are initially
face up double clicking them they will flip face down. This is my first swing project so I am at a lost of why they only respond one time. What I want to be able to do is after the first flipping be able to double click and have them flip back.
Code:
public class IconCardLabelMouseAdapter extends MouseInputAdapter {
....
public void mouseClicked(MouseEvent e) {
Icon disabledIcon = new ImageIcon("C:/Programming2009/MyNetBeansProjects/Poker/FiveCardStudB4/cards/b.gif");
JLabel lbl = (JLabel)e.getSource();
if (e.getClickCount() == 2) {
if(Deck.isUp(lbl.getName())) {
lbl.setDisabledIcon(null);//turn card up
lbl.setEnabled(true);
}
else {
lbl.setEnabled(false); //turn card down
lbl.setDisabledIcon(disabledIcon);
}
}
}
public class Deck {
private static JLabel[] iconCardLabels;
.....
public void addDragability() {
for(int i = 0; i < iconCardLabels.length; i++) {
IconCardLabelMouseAdapter iclma = new CardLabelMouseAdapter
(iconCardLabels[i]);
iconCardLabels[i].addMouseListener(iclma);
iconCardLabels[i].addMouseMotionListener(iclma);
}
public void faceDownDeck() {
Icon disabledIcon = new ImageIcon("C:/Programming2009/MyNetBeansProjects/Poker/FiveCardStudB4/cards/b.gif");
for(int i = 0; i < iconCardLabels.length; i++) {
iconCardLabels[i].setEnabled(false);
iconCardLabels[i].setDisabledIcon(disabledIcon);
iconCardLabels[i].setName(iconCardLabels[i].getName()
+ "," + "up");
}
}
public void faceUpDeck() {
for(int i = 0; i < iconCardLabels.length; i++) {
iconCardLabels[i].setDisabledIcon(null);
iconCardLabels[i].setEnabled(true);
iconCardLabels[i].setName(iconCardLabels[i].getName() + ","
+ "down");
}
}
public static boolean isUp(String name) {
boolean up = false;
String results[] = name.split(",");
if(results[results.length-1].equals("up")) {
up = true;
}
return up;
}
.....
}