My program is supposed to when a button is clicked, remove it and replace it with a label. In my program, the button is removed when clicked, but the label isnt added until another button is clicked, which removes hat button but then that label doesnt show.... and so on. Here is the code:
//adds buttons to screen if corresponding
//boolForButtons is true, else it
//displays label
public void addButtons() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (boolForButtons[i][j]) {
add(buttons[i][j]);
} else {
remove(buttons[i][j]);
add(labels[i][j]);
}
}
}
}
//refreshs the screen
public void refreshButtons() {
revalidate();
repaint();
addButtons();
}
//if button is clicked
public class event implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
//set the button clicked to not show on the screen
if (e.getSource() == buttons[i][j]) {
boolForButtons[i][j] = false;
}
}
}
refreshButtons();
}
}
thanks -