Discussion Locked

JFrame

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

5 replies

by sps19742001

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();
}
}

This discussion is closed to new replies.