嘿,我有两个 JFrame,一个是我的主登录框架,用户输入用户名和密码等...
登录后,用户将移动到主桌面程序。
例子:
当用户第一次加载并决定退出时,他们单击角落中的 x,这将调用我的 addWindowListener 事件,然后单击(取消)它不会执行任何操作。这就是我想要的。
但是,如果用户从我的登录表单登录到我的主桌面窗口,然后单击 x,它会在主窗口中调用 addWindowListener 事件并询问他们是否希望注销。问题是,当他们点击某个操作时,它会再次询问该操作。我已经检查过这一点,似乎每次调用新窗口时都会发生这种情况。
所以...可能的问题是我怎样才能让我的活动只被调用一次?
更多示例
启动程序>单击 X >单击“取消”(效果很好)
启动程序>登录>单击主窗口中的 X >单击“取消”(再次询问)
Hey all i have two JFrames one is my main login frame, user enters a username and password etc...
Once logged in the user is moved to the main desktop program.
Example:
When a user loads the first time and decides to exit they click the x in the corner this calls my addWindowListener event and they click (cancel) it does nothing. This is what i want.
However if a user logges in an goes from my login form to my main desktop window and then clicks x, it calles the addWindowListener event in the main window and asks if they wish to logout. Problem is when ever they click on an action it asks it again. I have checked into this and it seems to be happening each time a new window is called.
So... may question is how can i make my event only be called once?
Further examples
Start Program > Click X > Click Cancel (this works fine)
Start Program > Login > Click X in Main window > Click Cancel (asks again)
发布评论
评论(1)
1)不要使用两个 JFrames,使用 JDialog 与 JFrame 的父级/所有者
2)在某些事件上(正确登录后),您可以删除 JFrame 的 rel="nofollow">WindowListener (更好的是
JDialog
)1) don't use two JFrames, use JDialog with parent / owner for JFrame
2) on some of event (after correct logon) you can remove WindowListener from
JFrame
(better would beJDialog
)