Hi can anyone look at my code and tell me why when I click the JButton and have a checkbox selected my image array does not go through the images like before. any help appreciated :)
JButton btnSubmit = new JButton("Submit");
btnSubmit.addActionListener(new ActionListener() {
int currentIndex = -1;
public void actionPerformed(ActionEvent e) {
if (chckbxEyes.isSelected()== false && chckbxNose.isSelected()== false && chckbxMouth.isSelected()== false) {
currentIndex = (currentIndex + 1) % backgroundIcons.length;
lblMyFace.setIcon(backgroundIcons[currentIndex]);
}
if (chckbxEyes.isSelected()) {
currentIndex = (currentIndex) % eyesIcons.length;
lblEyes.setIcon(eyesIcons[currentIndex]);
}
if (chckbxNose.isSelected()) {
currentIndex = (currentIndex) % noseIcons.length;
lblNose.setIcon(noseIcons[currentIndex]);
}
if (chckbxMouth.isSelected()) {
currentIndex = (currentIndex) % mouthIcons.length;
lblMouth.setIcon(mouthIcons[currentIndex]);
}
if I change
if (chckbxEyes.isSelected()== false && chckbxNose.isSelected()== false && chckbxMouth.isSelected()== false) {
currentIndex = (currentIndex + 1) % backgroundIcons.length;
lblMyFace.setIcon(backgroundIcons[currentIndex]);
}
to
if (e.getSource() == btnSubmit) {
currentIndex = (currentIndex + 1) % backgroundIcons.length;
lblMyFace.setIcon(backgroundIcons[currentIndex]);
}
it works and goes through the array of image icons when I keep clicking the submit button. however, the background keeps changing when items are selected and I only want the background changed if no boxes are selected.
I hope you understand what i want to happen if not I am happy to clarify :)
Aucun commentaire:
Enregistrer un commentaire