Java action listener question
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
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.
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.
精彩评论