问题
Hi this problem is a little bit big.. I started my first big Java Project and right now I do not know how to close a JFrame without closing my whole project.
This are my project files: https://drive.google.com/open?id=0BxIXktk4GMkIMnd6ZXlLQnBHem8
I tried everything to close the JFrame loginRegisterWindow but with everything I tried the Frame stayed open ..
Has anyone a specific solution for my project how I could do this?
The code where the JFrame loginRegisterWindow should be closed should be in the class Login in the func package after the sentence "logged in has been printed".
NOTE: Please give feedback if you don't understand my question .. i am new to stack overflow
回答1:
You shouldn't use multiple JFrames
because it will bring a bad user experience and will be harder to maintain. Instead you should give a try to Card Layout or use JDialogs which will prevent the user from exiting your application or click behind.
But if you really need to use multiple JFrames, then you could use JFrame.DISPOSE_ON_CLOSE instead of JFrame.EXIT_ON_CLOSE
回答2:
try
yourJFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
I assume you have other threads processing your business logic, right? Otherwise, why care to keep Java alive?
来源:https://stackoverflow.com/questions/37732514/close-jframe-without-closing-my-whole-project