[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Converting from Object to Button

Posted on 1999-11-22
5
Medium Priority
?
228 Views
Last Modified: 2010-04-16
I have code like this:
public void mouseClicked(java.awt.event.MouseEvent 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?
0
Comment
Question by:clifABB
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
mattrope earned 200 total points
ID: 2225452
Try casting objTarget into an object of type Button like this:

Button btnTarget = (Button)objTarget;

0
 
LVL 6

Author Comment

by:clifABB
ID: 2225471
That's it!
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.
0
 
LVL 6

Author Comment

by:clifABB
ID: 2225475
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.
0
 
LVL 2

Expert Comment

by:mattrope
ID: 2225745
I don't think it did register--it doesn't show in the question history.
0
 
LVL 6

Author Comment

by:clifABB
ID: 2228161
mattrope:
I posted another question with the extra 25 points for your super quick answer:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=10236913 

Thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month8 days, 16 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question