Property Change Listener for an Array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Property Change Listener for an Array

  1. #1
    Join Date
    Feb 2003
    Posts
    17

    Question Property Change Listener for an Array

    Is it possible in any way to add an event listener to listen for changes made to an array of Strings.

    I have a private array of strings in one class, I wish its parent calling class to know when any values in this array list have been changed??


    Any usefull Ideas??

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560

    Two ways:

    You could isolate all updates to the array in a method, and implement a
    special method in the other class like:
    Code:
    // constructor
    
    public class SomeClass {
      private OtherClass otherClass=null;
    
      public SomeClass(OtherClass otherClass) {
        this otherClass=otherClass;
      }
    int [] array;
    .
    .
    .
    .
    private void setValue(int val, int pos) {
      array[pos]=val; 
      otherClass.listenMethod(int val, int pos);
    }
    Or you could isolate the array inside a class and supply it with a listener
    interface:
    Code:
    interface ArrayListener {
      public void valueChanged(int newVal, int oldVal, int pos);
    }
    
    public class BCArray {
      public int [] array=null;
      ArrayListener arrayListener=null;
    
      public BCArray(int [] array) {
        this.array=array;
      }
      public void setArrayListener (ArrayListener arrayListener) {
        this.arrayListener=arrayListener;
      }
      public void setValue(int val, int pos) {
        int oldVal=array[pos];
        array[pos]=val;
        arrayListener.valueChanged(val,oldVal,pos);
      }
    }
    Either way, the class that changes the array must have a pointer to the
    other class, either as an interface or as a plain instance reference.
    eschew obfuscation

  3. #3
    Join Date
    Feb 2003
    Posts
    17
    Thanks I'l have a bash at it!!

Similar Threads

  1. SQL DMO Restores in VB?
    By ObiWan in forum VB Classic
    Replies: 3
    Last Post: 05-23-2006, 11:35 AM
  2. Forcing Property Window to Update
    By Michael Welch in forum .NET
    Replies: 1
    Last Post: 12-07-2001, 11:14 AM
  3. Totally Lost and needing help...
    By Anthony M. Saffer in forum VB Classic
    Replies: 4
    Last Post: 09-05-2000, 11:28 PM
  4. ActiveX Control Property Pages
    By Jerry Bumgarner in forum VB Classic
    Replies: 4
    Last Post: 07-14-2000, 11:48 AM
  5. Replies: 3
    Last Post: 03-30-2000, 11:48 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center