Results 1 to 3 of 3
- 11-03-2011, 09:38 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
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.
I hope someone understands my problem and is able to explain me how to get classes to 'communicate' from bottom to top.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"); } }
Greetings,
Jelmer
- 11-03-2011, 10:06 PM #2
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".
- 11-03-2011, 10:16 PM #3
Member
- Join Date
- Nov 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Different ways of creating object
By krashh205 in forum New To JavaReplies: 1Last Post: 12-13-2010, 07:19 PM -
Need Help splitting up an Int in a variety of ways
By JoKeR313 in forum New To JavaReplies: 9Last Post: 11-10-2010, 06:22 AM -
communication between classes
By willemjav in forum New To JavaReplies: 10Last Post: 09-01-2008, 10:08 PM -
ways to get input from console
By soni in forum New To JavaReplies: 2Last Post: 05-05-2008, 09:44 PM -
Displaying characters in many ways.
By TampaTechGuy in forum New To JavaReplies: 7Last Post: 01-02-2008, 09:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks