Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

destroy Jframe object

Tags:

java

swing

jframe

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...

like image 204
jrdnsingh89 Avatar asked Mar 31 '13 19:03

jrdnsingh89


People also ask

How do you dispose of a JFrame?

exit(); causes the Java VM to terminate completely. JFrame. dispose(); causes the JFrame window to be destroyed and cleaned up by the operating system.

How do I remove all components from a JFrame?

removeAll(); startPanel = new StartPanel(); startPanel. setVisible(true); add(startPanel); revalidate(); repaint();

How do you close a JFrame programmatically?

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().

What is setDefaultCloseOperation JFrame Exit_on_close?

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.


1 Answers

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.

like image 163
DerpyNerd Avatar answered Oct 06 '22 05:10

DerpyNerd