Results 1 to 6 of 6
  1. #1
    trathanhcao is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default does java have delegate like c#

    Hi all,

    I want to invoke a method in class A from B like delegate in C# but i do not know how. I googled but i could not find any solutions to resolve my issue. Can any one help me to resolve thi problem.

    Thanks.

    Tra Thanh Cao

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: does java have delegate like c#

    Perhaps you could have A implement an interface.

    Otherwise, describe what you are trying to do. (rather than how you are trying to do it.)

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: does java have delegate like c#

    Also - this isn't an AWT/Swing question. I'll move it to New to Java.

  4. #4
    trathanhcao is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: does java have delegate like c#

    I have 2 classes named class A and class B
    In class A i create a jlabel named username
    In class B i create a button. All what i want is when i click on the button in class B i want to set text or do something to change text of label in class A.

    Please thanks.

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,944
    Rep Power
    19

    Default Re: does java have delegate like c#

    Sounds like some sort of listener to me.
    A listens for events (in this case a text change or some sort?) fired from B.

  6. #6
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: does java have delegate like c#

    I agree: add an action listener to the button (rather than assigning to the delegate).

Similar Threads

  1. Delegate Control from one Application to another
    By saikumarkomati in forum Advanced Java
    Replies: 4
    Last Post: 01-24-2009, 03:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •