Reputation: 127
I have a HashMap of JButtons which represents pictures.
this.nahledy.put(s.getName(), new JButton());
this.nahledy.get(s.getName()).addActionListener();
but I don't know how to tell the actionlistener which button has been pressed since the e.getActioncommand() is nothing and the s.getName() is already changed when user presses the button so I can't use it too.
Upvotes: 1
Views: 474
Reputation: 398
Its not perfect but maybe you can use something like this
public void actionPerformed(ActionEvent e) {
JButton source = (JButton)e.getSource();
Set<String> keys = nahledy.keySet();
for(String key : keys) {
if(nahledy.get(key).equals(source)) {
// do something with your button
}
}
}
This way you can find out the value of s.getName() you used for this button.
Upvotes: 1