Tracking changes in some central database by multiple objects scattered around the program

J

jb

Hi!
I've been writing a program that operates on small hand-made database.
And I would like other objects to track changes in this database
possibly in the swing way i.e:
class DataBase {
public void addActionListner(ActionListener foo){
//* What to put here *//
}

public void changePartOfDatabase{
/*....*/
fireActionPerformed();
}
}

Other objects interested in tracking changes would just add new
Listener.

I suspect that there is a class from I could inherit such functions -
but I hadn't been able to find it. ;-(. If there is please drop me some
keywords so I could google for it, if there is not please tell me how
to write such a thing by myself.
 
A

Andrew McDonagh

jb said:
Hi!
I've been writing a program that operates on small hand-made database.
And I would like other objects to track changes in this database
possibly in the swing way i.e:


class DataBase {
private List listeners =new ArrayList();

public void addActionListner(ActionListener foo){
listeners.put(foo);
}

public void changePartOfDatabase{
fireActionPerformed();
}

private void fireActionPerformed() {
for (int index = 0; index < listeners.length(); index++) {
ActionListener listener = (ActionListener)listeners.get(index);
listener.actionPerformed();
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top