swing - Logging out a user properly in java -


i'm using eclipse ide

i have code login -check if user , pass match -check if account's session column in db "logged in". if false log in user, else prompt user

when logging out, have log out button when clicked changes 'logged in' 'logged out'. problem when user didnt click log out button , instead closes application. tried making window listener when frame 'closing' redirecting log out button, kinda solves problem assigned every frame redirect log out button action when 'window closing'.

my app works this: app has multiple frames. after logging in there homepage, 4 more buttons direct other modules. in homepage, when click on module_a, homepage disposes , module_a frame pops up, if click 'back' button module_a disposes , homepage pop ups again, clicking module_b disposes homepage , pops module_b frame , on...

scenerio 1:

~logged in - changes user status 'logged out' 'logged in' redirects user log in page home page

~on homepage forgot close application, since have listener 'window closing' change 'logged in' state 'logged out' it's good.

scenerio 2:

~logged in - changes user status 'logged out' 'logged in' redirects user log in page home page

~on homepage click on module_a, dispose homepage , change 'logged in' status 'logged out' because homepage window closed.

how can fix scenerio 2? since closing frame logs me out im still using app different frame called modulea

ps. if guys dont understand im saying, please ask questions, ill answer fast can. im not @ explaining situation im sorry :'(

so guess have this:

void onwindowdispose() {     logmeout(); } 

what i'd suggest use counter:

int windowcount;  void onwindowcreate() {     ++windowcount; }  void onwindowdispose() {     --windowcount;      if(windowcount == 0)         logmeout(); } 

you might not use counter, hope idea. should log out when of windows closed, not 1 of them.

also, if "multiple frames" means "multiple jframes", please see "the use of multiple jframes, good/bad practice?"


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -