1
public void actionPerformed(ActionEvent e) {
i++;
ImageIcon icon = new ImageIcon(files[i].getAbsolutePath());
imagem.setIcon(icon);
frame.add(imagem, BorderLayout.CENTER);
}
});
I have an array of images, and the goal is always to press the button (event), the i iterator increments its value in a unit and mutes image.
But when I get to the end of the array (when there are no images), it gives me error and blocks the program. I know I have to do an if(files.lenght) but I’m not sure where to put it. Can someone help me? Thanks
What do you want to do? Count how many times the user has clicked the button?
– Jéf Bueno
Where’s the increment in the code? You wouldn’t happen to be popping the array size? Add a [mcve] by editing the question.
– user28595
am popping yes, I edited the post. The if condition is that it’s messing me up
– rrr
Add the stack of errors as well.
– user28595
@jbueno when reaching the end of the array size I want not to error, and to launch an exception for example
– rrr