> I've got 9 buttons that are presented with one icon, and when I press that
> button I want to change it, but
[quoted text clipped - 28 lines]
> but since my buttons are Array obj. I can't say:
> buttonSource.setIcon(paint[1]);
Actually, you can, but you need to cast buttonSource to a JButton.
JButton buttonSource = (JButton)e.getSource();
buttonSource.setIcon(paint[1]);
That should work. e.getSource() will return the Object that created
the event, in this case *one* of the 9 buttons. e.getSource() return
type is Object, because the source "could" be anything, but in this
case you know it is a JButton, and just need to cast. To be on the
safe side, you probably should check instanceof JButton, although this
isn't something I do often, but I'm not usually a GUI programmer.
Well, good luck.
-Daniel.
man4*.* - 06 Nov 2006 09:58 GMT
> Actually, you can, but you need to cast buttonSource to a JButton.
>
> JButton buttonSource = (JButton)e.getSource();
> buttonSource.setIcon(paint[1]);
THX, now I understand what get wrong...