How can I destroy the Jframe object(like no references should be left) because I am implementing multi user login system to itunes like app so a user can add songs delete songs. I have 3 frames loginFrame, adminFrame, nonAdminFrame.. loginFrame = to login which starts nonAdminFrame where the add deleting songs are taken careof The login is being handled as I have data folder where .txt files are used to write user objects which has the song info type linked lists. The way i login I look into the data folder and see if there is .txt file named user1.txt file and it will load up all data into nonadminFrame... The problem is login is not working properly as it as references to older nonAdminFrame where the previous user data is still present...
I have 3 classes or 3 JFrames. The mainclass is loginFrame. I get the login info and see if the user is admin or nonadmin and then show the admin or nonadminFrame by creating a new adminFrame() object or nonAdminFrame() object and i set loginFrame.setVisible(false); The problem is with nonAdminFrame where the all itunes library stuff happens. I have JTree to show all the songs for that user and once the clicks logout I dispose of the nonAdmin frame using frame.dispose() but if I login again with a different again creating a nonadminFrame() object I see old user's data in the JTree that the problem...
exit(); causes the Java VM to terminate completely. JFrame. dispose(); causes the JFrame window to be destroyed and cleaned up by the operating system.
removeAll(); startPanel = new StartPanel(); startPanel. setVisible(true); add(startPanel); revalidate(); repaint();
You can close the frame programmatically by sending it the WINDOW_CLOSING event, like this: WindowEvent closingEvent = new WindowEvent(targetFrame, WindowEvent. WINDOW_CLOSING); Toolkit. getDefaultToolkit().
setDefaultCloseOperation() EXIT_ON_CLOSE — Exit the application. JFrame. HIDE_ON_CLOSE — Hide the frame, but keep the application running. JFrame. DISPOSE_ON_CLOSE — Dispose of the frame object, but keep the application running.
Is there a way in your user1.txt file to notice if that user is an administrator or not? Your question isn't very clear, but you should be able to do something like this:
JFrame frame = new JFrame();
frame.dispose();
The compiler will literally dispose of this frame and automatically clean up using the garbage collector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With