Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-10-2008, 04:09 PM
Member
 
Join Date: Nov 2008
Posts: 2
Rep Power: 0
barts2108 is on a distinguished road
Cool Register a callback function in other class
Hi All

I am working on a program that contacts a PLC (programmable logic controller) using Java.

I have one class (Class A) that contacts the PLC and is able to add listeners for items changed inside the PLC (for example Input/Output changes).

Another class is the LED class (Class B). This graphically drawing a circle meant to show the status of an input or output.

Now I want the Class B to invoke a 'registration function' in Class A passing which Input/Ouput to observe. Class A then must create a listener function for that Input/Output. When the Input/Output changes the listener function will be called (this is handled by the PLC manufacturer software). The listener for that IO then must invoke a method in the Class B so that I can paint the correct status

The window handling, led painting (Class B) and PLC connection (Class A) I can all get to work. If I instantiate the LED from Class A it even works, however, I do not want the Class A to know anything about which items will be used.

Thus if I want to show the IO status with a LED I use a LED Class (Class B) or if I prefer a BarGraph, I will create a Class C.

Hope it is a bit clear what I want to establish. Almost all is working except that the LED class can register itself to de PLC Class to get a callback when the item changes.

Any hints / code samples would be highly appreciated. I am experienced programmer (VB, C) but just started with Java.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-10-2008, 05:11 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: SouthWest Missouri, USA
Posts: 2,229
Rep Power: 4
Norm is on a distinguished road
Default
Quote:
want the Class B to invoke a 'registration function' in Class A
Look at any of Java's listeners for the template.
Create an interface for the listener and have B implement it.
In B call an add<your listener>(<your interface>) method in A passing a this reference.
Have the add method save the reference. When A want to tell B something it calls the interface method as defined in the interface.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-10-2008, 05:24 PM
Member
 
Join Date: Nov 2008
Posts: 2
Rep Power: 0
barts2108 is on a distinguished road
Default
Norm,

Thanks for the quick answer. Going to work on this and will feedback the result.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with get function calicocal New To Java 10 11-09-2008 08:59 PM
Setting a timeinterval callback ??? wallys New To Java 1 08-19-2008 06:52 PM
Need a little help with a function! Nuluvius New To Java 3 02-08-2008 12:33 AM
can't register a MySQL driver prfalco New To Java 4 02-04-2008 12:13 AM
I want to add function romina New To Java 1 08-07-2007 06:25 AM


All times are GMT +2. The time now is 06:45 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org