How do i find if a window is opened on swing

前端 未结 3 1044
夕颜
夕颜 2020-12-30 11:48

I have a problem with my application where the user will open more than one window at a time. And i have added dispose() method to call on closing the window. Now i should k

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-30 12:34

    Just a possible approach...

    Create a class, call it WindowManager, that manages creation and disposal of windows.

    It could for example retain the count of the windows currently open, and allow a dispose operation only if there are more than one windows "alive", otherwise show a confirm message with JOptionPane telling the user "Really close? That would terminate the application." or something like that.

    The "tricky" part is that you have to do this kind of window-related operations throughout the WindowManager, otherwise everything would screw up.

    Dunno if Swing has something like this built-in, I've never seen such a scenario.

提交回复
热议问题