Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to wait for a JFrame to close before continuing?

My program consists of 3 main 'sections'. Main function, Login form and App form. The main function should do something like: Open Login form, wait for it to close, then open App form. I can't get the waiting part to work, or rather, I don't know how I would go around doing that.

I was told by someone to use a JDialog instead and use setModal(true), but with that approach the Login form wouldn't appear on the taskbar, which is terrible in my opinion.

Another thing I considered was to open the App from inside the Login after it closes, but that feels like bad design since that'd make the Login form non-reusable.

So, please, what would you suggest?

like image 695
argoneus Avatar asked Sep 09 '12 01:09

argoneus


People also ask

How do I close a JFrame without closing another?

You can use setVisible(false) on your JFrame if you want to display the same frame again. Otherwise call dispose() to remove all of the native screen resources. thanks,but i close the window with the close-button at the upper-right corner.

Is there a way to wait in Java?

wait() Method in Java With Examples Inter-Thread communication is a way by which synchronized threads can communicate with each other using the methods namely wait(), notify() and notifyAll(). wait() method is a part of java. lang. Object class.

How do I automatically close a JFrame?

DISPOSE_ON_CLOSE (defined in WindowConstants) : Automatically hide and dispose the frame after invoking any registered WindowListener objects. EXIT_ON_CLOSE (defined in JFrame) : Exit the application using the System exit method. Use this only in applications.

How do you make a JFrame close when a button is pressed?

You can use super. dispose() method which is more similar to close operation. Show activity on this post. You cat use setVisible () method of JFrame (and set visibility to false ) or dispose () method which is more similar to close operation.


1 Answers

  • Why must the login appear on the task bar, since the main app will be there, and you don't want more than one task bar item for an individual program. Your best option may be to use a modal JDialog.
  • Another option is to use CardLayout to swap "views".
  • A third option is to use a JFrame if you must but attach a listener to it, a WindowListener I believe, to respond to its close event.
  • Regardless of which route you go, your login gui should be a JPanel so that you can place it anywhere you wish and then change your mind later.
like image 72
Hovercraft Full Of Eels Avatar answered Oct 17 '22 03:10

Hovercraft Full Of Eels