In a for loop, I want to
- initialize JButtons [] bts .
- add the buttons to a panel pan3 .
- add an ActionListener to each JButton .
here what I've got so far :
for(int i = 0 ;i < bts1.length ; i++){
bts1[i] = new JButton(""+i);
pan3.add(bts1[i]);
//The NullPointerException happens after this line .
bts[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
int j = 0 ;
screen.setText(screen.getText()+bts[j].getText());
j++;
}
});
}
My question is how to solve the NullPointerException ? note for the j I add it because when I tried to use the i , a compiler error occurs ,