Hi Kapilkp,
Same time ago, I did something like that.
In login JFrame you must set the close operation as:
f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
And when you click on the button, you have dispose this frame:
dispose();
and create a new instance of your class that store the second JFrame
dispose();
JSecondFrame secondFrame = new JSecondFrame();
I hope this helps you
Best regards,
Filipe Marques
--UPDATE--
import javax.swing.*;
import java.awt.event.*;
public class MyLogin {
private JFrame f = new JFrame("Login");
private JButton bok = new JButton("OK");
public MyLogin() {
f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
f.getContentPane().add(bok);
bok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
f.dispose();
new SecondFrame();
}
});
f.setSize(100,100);
f.setVisible(true);
}
public static void main(String[] args) {
new MyLogin();
}
}
import javax.swing.*;
public class SecondFrame {
private JFrame f = new JFrame("Second");
public SecondFrame() {
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300,300);
f.setVisible(true);
}
}
The login JFrame is only a button and when you click it, the login window is disposed and the second window appears.