i have created a matrix with button and i want to listen event of this matrix. i need to take coordinates of matrix (X Y) when a button clicked and i ll use this coordinate for my other operations in code but i couldnt find a solution get coordinates
this is snippet of my code
private void BlockButtonSec() {
secim=1;
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
butonlar[i][j].addActionListener(this);
}
}
for (int i = 0; i < 50; i++) {
for (int j = 0; j < 50; j++) {
gecici=butonlar[i][j];
gecici.addActionListener
(new ActionListener() {
public void actionPerformed(ActionEvent event) {
coordinate_x=i;
coordinate_x=j;
sent(coordinate_x,coordinate_y);
setbackgroundofthisbutton();
}
});
}
}
and other my idea is taking out actionperformed side like that:
public void actionPerformed(ActionEvent e) {
// JButton tiklandi=new JButton();
if(secim==1){
butonlar[i][j].se
// tiklandi.setBackground(Color.RED);
}
}
this code is not completed --> butonlar[i][j].se because i,j is not available but i couldnt sent i,j
just i need an idea that:
when i clicked a button how can i change any button color in buttons of matrix and how can i get coordinates from buttons of matrix