views:

57

answers:

2

I am creating a custom JPanel element (a login form).

I want to allow people who use my panel to subscribe/listen to an event called "loginSuccessful".

What is the best way to implement this in my JPanel object?

UPDATE: oh and i also want to add that when that action is triggered, i also want to return a "User" object containing the person that was just logged in

+3  A: 

I normally prefer EventBus for those kinds of Events.

Library and Examples can be found here

Moreover you should consider to keep businesslogic out of your viewclass (panel) and create some kind of LoginController for your loginbusinesslogic. There are plenty of good examples out there.

EDIT: You can send an UserObject within an EventBusEvent as well.

ymene
Thanks for the link, I didn't know about the EventBus and it may prove to be just what I needed right about now.
Stephen P
A: 

I would start by separating your code form widget code. Don't extend where you don't need to. Where classes are focussed on a particular job, everything becomes so much easier.

Tom Hawtin - tackline