Make your frame class as SINGLETON.
getInstance() always return the same instance
package shashikant;
import javax.swing.*;
public class MyFrame {
private static JFrame f2;
private static MyFrame thisClass;
private static final String str = "<html>" + " ... " + "</html>";
private MyFrame() {
JLabel strLabel;
JPanel p2;
JScrollPane jsp;
f2 = new JFrame("shashikant verma");
p2 = new JPanel();
f2.getContentPane().add(p2);
strLabel = new JLabel(str);
p2.add(strLabel);
jsp = new JScrollPane(strLabel);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
f2.getContentPane().add(jsp);
////
f2.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
f2.pack();
f2.setVisible(true);
}
public static MyFrame getInstance() {
if (thisClass == null) {
thisClass = new MyFrame();
}
return thisClass;
}
public void setVisible(boolean b) {
f2.setVisible(b);
}
} Implementation of OpenMenuListener
package shashikant;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class OpenMenuListener implements ActionListener {
// a - definition
public void actionPerformed(ActionEvent ev) {
if (ev.getSource().equals(a)) {
MyFrame.getInstance().setVisible(true);
}
}
//test
public static void main(String args[]) {
MyFrame.getInstance().setVisible(true);
}
}