I'm just starting to get used to listeners but I am still kind of new to working with them. I need to reference a button inside of its actionlistener to get the text of that button. my code I want is:
for(int i = 0; i<48; ++i){
button[i] = new JButton("");
contentPane.add(button[i]);
button[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
x_marks_the_spot();
if(button[i].getText().equals("X")){
increase_hit();
}
else{
increase_miss();
}
}
});
Obviously I can't do this because [i] doesn't actually exist in the anon portion of code. I am sure there is a way to do this by getting the source, but I can't think of it.