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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top