문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top