clifABB
asked on
Converting from Object to Button
I have code like this:
public void mouseClicked(java.awt.even t.MouseEve nt event)
{
Object object = event.getSource();
if (object == cmdPlay0 ||
object == cmdPlay1 ||
object == cmdPlay2 ||
object == cmdPlay3 ||
object == cmdPlay4 ||
object == cmdPlay5 ||
object == cmdPlay6 ||
object == cmdPlay7 ||
object == cmdPlay8)
cmdPlay_MouseClicked(event , object);
}
Passing the object to cmdPlay_MouseClicked. In the procedure cmdPlay_MouseClicked, I want to reference the specific button clicked. Something like this:
void cmdPlay_MouseClicked(java. awt.event. MouseEvent event, Object objTarget)
{
Button btnTarget = objTarget;
if (btnTarget.getLabel() != "X") {
btnTarget.setLabel("X");
}
}
The problem is that it doesn't want to convert objTarget to btnTarget.
How do I do this?
public void mouseClicked(java.awt.even
{
Object object = event.getSource();
if (object == cmdPlay0 ||
object == cmdPlay1 ||
object == cmdPlay2 ||
object == cmdPlay3 ||
object == cmdPlay4 ||
object == cmdPlay5 ||
object == cmdPlay6 ||
object == cmdPlay7 ||
object == cmdPlay8)
cmdPlay_MouseClicked(event
}
Passing the object to cmdPlay_MouseClicked. In the procedure cmdPlay_MouseClicked, I want to reference the specific button clicked. Something like this:
void cmdPlay_MouseClicked(java.
{
Button btnTarget = objTarget;
if (btnTarget.getLabel() != "X") {
btnTarget.setLabel("X");
}
}
The problem is that it doesn't want to convert objTarget to btnTarget.
How do I do this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mattrope:
I increased the points to 75, but I don't think it registered. If not, let me know and I'll post an additional question.
I increased the points to 75, but I don't think it registered. If not, let me know and I'll post an additional question.
I don't think it did register--it doesn't show in the question history.
ASKER
mattrope:
I posted another question with the extra 25 points for your super quick answer:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10236913
Thanks
I posted another question with the extra 25 points for your super quick answer:
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10236913
Thanks
ASKER
I knew there was a way to do this, but I could find nothing about it in the tutorials I had read.
Thanks a lot.
An extra 25 for such a quick answer.