So I'm trying to implement a guess and check game where there are letters of the English alphabet displayed then each time one is clicked it goes away if it wasn't part of the word specified. (I guess you can call it hangman but there's going to be more to it). Then once the game is lost setLetters is called again and should reset all the letters back onto the screen. (that's another problem i haven't solved in this and know belongs between the update and setLetters() )
letters = new JLabel[26];
for (int i = 0; i < 26; i++) {
int ch = 'A' + i;
letters[i] = new JLabel("" + (char) ch);
panel.add(letters[i],c);
}
ctrl.setLetters(letters);
in the ctrl class there is
public void setLetters(JLabel[] letters2) {
letterLabel = letters2;
for (int i = 0; i < letters2.length; i++) {
letterLabel[i].addMouseListener(this);
/* i'm assuming this issue is here with adding tons of mouselisteners to the label each time it resets, but i'm not sure how to fix it */
}
}
@Override
public void mousePressed(MouseEvent e) {
for (int i = 0; i < 26; i++) {
if (e.getSource() == letterLabel[i]) {
if (!game.letterAvailable((letterLabel[i].getText().charAt(0)))){
letterLabel[i].setText(" ");
}
else {
game.makeGuess((letterLabel[i].getText().charAt(0)));
}
}
}
update();
}
public void update() {
if (letterLabel != null) {
setLetters(letterLabel);
}
if (panel != null) { // redraw (not important for this error)
panel.repaint();
};
}
the error I get is exponentially that of:
java.awt.AWTEventMulticaster.mouseExited(Unknown Source) OR java.awt.AWTEventMulticaster.mouseExited(Unknown Source)
depending on how the letters are clicked (have yet to figure out why)