How to display panel which is of Singleton class in two different frames at a time?

Posted by Sriku on Stack Overflow See other posts from Stack Overflow or by Sriku
Published on 2010-04-29T08:09:56Z Indexed on 2010/04/29 8:27 UTC
Read the original article Hit count: 212

Filed under:
|

I am trying to display a singleton obj on two different Jframe, but it is displayed only in the Jframe in which the object is added at last ( in example Frame2). Other Jframe is empty. This Singleton class is inherited from Panel and contains a label in it. Can anybody please tell me how can i display this singleton object in two different frame ?

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() 
{
public void run() {
 NewJFrame inst = new NewJFrame();
 inst.setTitle("Frame1");
 inst.setSize(300, 300);
 inst.setLocationRelativeTo(null);
 inst.setVisible(true);
 singltonpanel _sin = singltonpanel.instance();
 inst.add(_sin);
 inst.repaint();
 JFrame frame = new JFrame("Frame2");
 frame.setSize(300, 300);
 frame.setVisible(true);
 singltonpanel _sin1 = singltonpanel.instance();
 frame.add(_sin1);
 frame.repaint();
}
});

© Stack Overflow or respective owner

Related posts about java

Related posts about swing