Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: how to determine type of component of listener's source

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default how to determine type of component of listener's source

    I want to do is:

    if the source is a JLabel then....
    and if the source is a JButton then....

    but:

    MouseListener mL = new MouseAdapter(){
    @Override
    public void mouseEntered(MouseEvent me){
    if(me.getSource() .......){
    //NO IDEA ANYMORE!
    }
    }
    };

    please help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to determine type of component of listener's source

    if the source is a JLabel then....
    and if the source is a JButton then....
    You could use the instanceof operator to test what datatype an object is.

    Please explain what you are trying to do.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    26
    My Mood
    Aggressive
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: how to determine type of component of listener's source

    i cant explain any better than this..

    i have lots of components like buttons and labels that has the same Listener, now i want the listener to tell me what kind of source he got (JButton or JLabel) when that listener is executed..

    thats all i can say

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to determine type of component of listener's source

    tell me what kind of source he got (JButton or JLabel)
    see my last post about instanceof
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: November 3rd, 2012, 01:20 AM
  2. How to Determine if a String is a Word or Number?
    By megnog in forum Java Theory & Questions
    Replies: 18
    Last Post: April 19th, 2012, 04:31 PM
  3. Replies: 2
    Last Post: November 2nd, 2011, 05:22 AM
  4. How to make Java determine if a values is an integer or not.
    By MiniatureBeast in forum Object Oriented Programming
    Replies: 5
    Last Post: August 17th, 2011, 11:32 PM
  5. [SOLVED] Help; algorithm to determine 'range'
    By b_jones10634 in forum Algorithms & Recursion
    Replies: 13
    Last Post: August 24th, 2010, 04:57 PM