I am new to SO, but I am really lost with this... I have declared and instantiated an array of 10 JButtons in Java Swing. I have also done the same for an array of my 10 custom object (Crime). What I want to do is when each button is clicked, I want a JOptionPane to display the crime details Here is my code:
for(int i=0; i<buttons.length; i++){
buttons[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, crimes[i].getDescription(), "Crime", JOptionPane.INFORMATION_MESSAGE, null);
I keep getting an array out of bounds exception which makes no sense since there are the same number of elements in each array?
Aucun commentaire:
Enregistrer un commentaire