Addramyr
Addramyr

Reputation: 354

Java Swing: addWindowListener repeating

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)

Upvotes: 1

Views: 511

Answers (1)

mKorbel
mKorbel

Reputation: 109815

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 be JDialog)

Upvotes: 1

Related Questions