authentication - How to prevent a window to load if it has not previously gone through the stage of login in Java? -
i have made program in java has 2 windows (jframes):
a) log-in window,
b) main window.
the correct way run program run first "log-in window" , if username , password correct, window redirects "main window", making "log-in window" dispose.
but
if runs directly "main window" (ignoring log-in stage), window run correctly without authentication...
so
how can prevent "main window" loading , running if runs directly (e.g.>> java main_window
)? want program run only order (1) "log-in window" , (2) "main window".
edit
the main_window
class has 1 main
method below code:
public static void main(string[] args) { eventqueue.invokelater(new runnable() { public void run() { try { final main_window frame = new main_window(); frame.setlocationrelativeto(null); frame.setvisible(true); frame.addwindowlistener(new windowadapter() { public void windowclosing(windowevent e) { torunonclose(); frame.dispose(); } }); } catch (exception e) { e.printstacktrace(); } } }); }
suggestions:
- your login window should modal dialog, such jdialog, not jframe.
- your gui should have one main method, method calls login modal dialog first, , if successful, opens main jframe after this.
the main main method like:
private static void createandshowgui() { logindialog logindialog = new logindialog(); logindialog.setvisible(true); // verify user authentic if (logindialog.verify()) { maingui maingui = new maingui(); maingui.setvisible(true); } } public static void main(string[] args) { swingutilities.invokelater(new runnable() { public void run() { createandshowgui(); } }); }
in example above, since logindialog modal, code below logindialog.setvisible(true)
not run until dialog window no longer visible.
regarding questions:
1) run code @ loading time of main window,
run in single 1 main method.
2) how can set , feel (later) without main method
you'll have main method, one main method.
3) how can run code when frame closes (as doing now)?
do same thing in single main method.
Comments
Post a Comment