Link to home
Start Free TrialLog in
Avatar of boukaka
boukakaFlag for Canada

asked on

notificationlistener

Does anyone know of a good tutorial for beginners on how to create an interface with a notification listener that listens to a class and how to observe it from another class?

I have a class called ODSLoader that I need to listen to - I have the basic structure of the interface (I think) but I have no idea how to code it to actually listen to ODSLoader.

public interface Notifier {
         public interface NotificationListener {
             public void onNotificationPosted();           
            
         }

         public void addListener(NotificationListener listener);
         public void removeListener(NotificationListener listener);
      }

I then have another class with a progress bar that needs to be notified when to progress but I have no idea how to do that either...

This is my progress bar

            progressBar = new JProgressBar(0,100);
            progressBar.setValue(0);
            springLayout.putConstraint(SpringLayout.NORTH, progressBar, 12, SpringLayout.SOUTH, btnProcess);
            springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST, frame.getContentPane());
            springLayout.putConstraint(SpringLayout.EAST, progressBar, -10, SpringLayout.EAST, frame.getContentPane());
            frame.getContentPane().add(progressBar);

Can anyone point me in the right direction or show me how to code it?
Thanks
SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think googling for java observer pattern will get you a lot of useful links.
Avatar of boukaka

ASKER

The two files are attached... thanks
ODSLoader.java
ODSLoaderAppWindow.java
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boukaka

ASKER

Ok, so I have to go figure out how to pass an "instance" and I think I'm good.
Avatar of boukaka

ASKER

Thank you very much for all your help!
@boukaka,

I gave you quite a bit of the code that you needed in my first comment, and zzynx followed up with some more in another comment.

Do you think that the points should have been split between the two of us?
I agree that a split would have been more fair.
You can ask for a reopen of this question and once it is, you can close it again giving both of us points.
Avatar of boukaka

ASKER

Oh sorry, just noticed this. Where to I ask for a re-open?
Thanks,
Avatar of boukaka

ASKER

Points have been split 50/50 now. Sorry about that.
No worries, thanks for resolving it! :)