Typcasting to a JButton

I'm playing with buttons and action listener, and I need to take a captured object and cast it as a JButton so I can use its positioning methods (I want to click one button, then another, and have them switch positions)

public void actionPerformed(ActionEvent e)

{

Object selected = e.getSource();

//JButton temp = selected;

}

Can Objects be typecast in Java? I found a page that said you could define any object up or down an inheritance tree and it would be fine, but that's not the case.

Any help would be appreciated. Thanks.

[580 byte] By [Hybrida] at [2007-11-27 8:28:04]
# 1
Correct syntax requires the cast operator:Object selected = e.getSource();JButton temp = (JButton) selected;
Hippolytea at 2007-7-12 20:17:54 > top of Java-index,Java Essentials,New To Java...
# 2
Hah, I actually just stumbled across that as you posted it.I was trying JButton(selected) and other things.Mixing up my syntax ~.~Thanks!
Hybrida at 2007-7-12 20:17:54 > top of Java-index,Java Essentials,New To Java...