Results 1 to 3 of 3
  1. #1
    jelmer91 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Communication between two classes, both ways.

    Hi there,

    I have been programming in actionscript3 ( adobe flash ) for quite a while now, and i wanted to rewrite some simple programs i made there, but this time in Java. However, i came upon this... well, problem :) When trying to communicate between two classes, in flash i could just dispatch events in sub classes, and listen for them in the top classes. In Pseudo-code, here is what i am trying to do.

    Java Code:
    ClassA{
    public ClassB b = new ClassB();
    b.addListener("ListenForThis",functionToCall);
    b.doThisFunction();
    
    private void functionToCall(Event e){
    System.out.println("ClassB Dispatched the event");
    }
    }
    
    ClassB{
    private void doThisFunction(){
    dispatchEvent("ListenForThis");
    }
    }
    I hope someone understands my problem and is able to explain me how to get classes to 'communicate' from bottom to top.

    Greetings,

    Jelmer

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Communication between two classes, both ways.

    Are you writing a GUI? If so there are Listeners available in the Swing classes. If not then it sounds like you want to look up "call back methods".

  3. #3
    jelmer91 is offline Member
    Join Date
    Nov 2011
    Posts
    2
    Rep Power
    0

    Default Re: Communication between two classes, both ways.

    yes! You are brilliant :) The Callback Methods was exactly what i needed, thanks so much for the quick reply :)

Similar Threads

  1. Different ways of creating object
    By krashh205 in forum New To Java
    Replies: 1
    Last Post: 12-13-2010, 08:19 PM
  2. Need Help splitting up an Int in a variety of ways
    By JoKeR313 in forum New To Java
    Replies: 9
    Last Post: 11-10-2010, 07:22 AM
  3. communication between classes
    By willemjav in forum New To Java
    Replies: 10
    Last Post: 09-01-2008, 11:08 PM
  4. ways to get input from console
    By soni in forum New To Java
    Replies: 2
    Last Post: 05-05-2008, 10:44 PM
  5. Displaying characters in many ways.
    By TampaTechGuy in forum New To Java
    Replies: 7
    Last Post: 01-02-2008, 10:16 PM

Posting Permissions

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