OK so i dynamically made a line of J Buttons on a J Panel with a null layout using this code:
int Y = 100;
int X = 100;
for(x=1, x<=20, x++){
button = new JButton(x);
button.setLayout(null);
button.setSize(100, 100);
button.setLocation(X,Y);
button.setVisible(true);
panel.add(button);
X += 100;
//action listener
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//should print out the location of the button that was clicked
System.out.println(button.getLocation());
}
});
}
and i when i press on of does button i want it to print its location on the panel but instead it prints out the location of the last button that was added every time, please help.
take note that i am a very new to programming