Click here to Skip to main content
13,355,311 members (59,899 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 7 Oct 2003

Illustration of a Java type listener method for MFC

, 7 Oct 2003
Rate this:
Please Sign up or sign in to vote.
An article on how to make a 'Java type' listener method.


This article was written to illustrate how to implement the 'Java type' listener method in MFC. This small article demonstrates how you can take advantage of this method and how you can use it in your code. This is my first project, so if there is anything wrong with it or if there is anything better that can be implemented, please do mail me at In general, this code can also be roughly seen as the implementation of the 'Observer Pattern'. You can get more information on the observer pattern from the Houston's page and Wiki's page.


There is currently an article present in CodeProject which implements the 'Observer Pattern' to illustrate a treadmill, but I have written this article purely to illustrate the 'Java Listener method' and nothing else.

Using the code

When you need to make a class an observer to the event source, you need to inherit your class from CJrtEventListener and implement the EventHandler method.

EventHandler is the method where you want the particular action to be performed. For e.g.: In the project, I have four 'Listeners', each 'Listener' wants to perform a different action when the source changes. So all the 'Listeners' have a different EventHandler function.

The 'Source' to which the 'Listeners' are supposed to listen to, is the edit box with a 'Change Event Source' button next to it.

The buttons in the control panel (at the top), controls the 'Listeners'. When the control panel button in switched on, the respective 'Listeners' start to listen for the source and when it's switched off, the respective 'Listeners' stops listening to the source. These buttons also show the state of the respective 'Listener'.

CJrtEvent is the event class that is passed to the 'Listeners' so that they know that this is the event occurred, and update themselves.

CJrtEventSource is the source, which means that this is what your 'Listeners' will be listening for.

All the 'Event class' and the 'Listener class' are kept decoupled, so both of them don't have to know about each others existence.

Points of interest

While writing this article I came to know of the mechanics of how the 'Java Listeners' work. Actually I needed to implement the Java 'Listening' method in my MFC project. I asked my teacher and he said that since MFC does not provide a 'Listener' like Java, I'll have to make my own. So this project is what I've come up with


Thanks to my teacher Dr. Zhang Binglu for guiding and helping me.


Well, at last if you think this article is useful to you, perhaps I can upgrade it to use C# and Windows forms.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

R. Thomas
Web Developer
Singapore Singapore
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 2 Pin
Niklas Lindquist31-Mar-09 4:15
memberNiklas Lindquist31-Mar-09 4:15 
GeneralMy vote of 2 Pin
Niklas Lindquist31-Mar-09 4:14
memberNiklas Lindquist31-Mar-09 4:14 
QuestionDiagrams? Pin
Johann Gerell8-Oct-03 12:04
memberJohann Gerell8-Oct-03 12:04 
AnswerRe: Diagrams? Pin
snakeware8-Oct-03 21:51
membersnakeware8-Oct-03 21:51 
GeneralRe: Diagrams? Pin
Johann Gerell9-Oct-03 0:41
memberJohann Gerell9-Oct-03 0:41 
AnswerRe: Diagrams? Pin
Joseph R. Thomas9-Oct-03 0:51
memberJoseph R. Thomas9-Oct-03 0:51 
actually first i wanted to use the Observer pattern...
if you look at the observer pattern article available in CP//
illustrating the straitmaster example..
at first i tried to follow it...but i realised following it made my Listener/Observer/Subscriber and my EventSource tightly bonded!
i wanted to keep them decoupled so thats why i followed my teachers example instead..Smile | :)

Have a Super Blessed Day!
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
"For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life."
John 3:16
"Therefore you also be ready, for the Son of Man is coming at an hour you do not expet."
Luke 12:40

GeneralRe: Diagrams? Pin
Johann Gerell9-Oct-03 1:26
memberJohann Gerell9-Oct-03 1:26 
GeneralRe: Diagrams? Pin
Joseph R. Thomas9-Oct-03 6:19
memberJoseph R. Thomas9-Oct-03 6:19 
GeneralRe: Diagrams? Pin
danitrol15-Oct-03 21:58
memberdanitrol15-Oct-03 21:58 
GeneralRe: Diagrams? Pin
Johann Gerell15-Oct-03 22:42
memberJohann Gerell15-Oct-03 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 8 Oct 2003
Article Copyright 2003 by R. Thomas
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid