General discussion

Locked

JFrame

By ahiral ·
i am devloping on application where i am calling a class on button click which again on JFrame,now i want to close the Jframe from which i am calling another JFrame.
if i say setVisible(false); then first Jframe will not visible but it remains in memory..i don't want this..can you guide me.if you can pass me some code it will be great...

thanks
Hiral

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
Thread display: Collapse - | Expand +

All Comments

Collapse -

JFrame

by okujava In reply to JFrame

just call dispose(), then it will be garbage collected.

cheers

s.okujava

Collapse -

JFrame

by ahiral In reply to JFrame

The question was auto-closed by TechRepublic

Collapse -

JFrame

by sps19742001 In reply to JFrame

We ca use dispose() method.
Sample code provided.please see it.i think it will
solve ur probs.
thanks,
Santhu.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Exp extends JFrame
{

private JButton click;
public Exp()
{
this.getContentPane().setLayout(new FlowLayout());
click = new JButton("ClickMe");
click.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
showAnotherFrame();
}
});
this.getContentPane().add(click);
this.setTitle("baseframe");
this.setSize(250,150);
this.setVisible(true);
this.setLocation(100,150);
}
private void showAnotherFrame()
{
JFrame jframe = new JFrame();
jframe.setTitle("newframe");
jframe.setSize(250,150);
jframe.setVisible(true);
jframe.setLocation(200,150);
this.dispose();
}

public static void main(String args[])
{
new Exp();
}
}

Collapse -

JFrame

by ahiral In reply to JFrame

The question was auto-closed by TechRepublic

Collapse -

JFrame

by ahiral In reply to JFrame

This question was auto closed due to inactivity

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums