I have 2 swing classes that extend with JFrame . Both have a show() method in the constructor. From ClassOne I called ClassTwo as new ClassTwo() on a button click event. But if I press the button again, a new window for ClassTwo will open. So, how can I stop a ClassTwo window from opening if one ClassTwo window is open?
Edit
Now this problem is being solved, but now, when I open the ClassTwo window, it shows one window. Then, closing it, when I open the ClassTwo window again, it opens two windows, and this count continues to increase. Why is this happening?
EDIT 2
I found that this is not a swing problem, but a problem with it from the Samck MultiUsreChat API class. Therefore, everyone who worked on this helps me.
code in ClassOne:
if(!winList.contains(room_jid)){ new ClassTwo(room_jid,....); winList.add(room_jid); }
and in ClassTwo:
public ClassTwo(....){ ...... this.muc = new MultiUserChat(connection, room_jid); if(!muc.isJoined()) muc.join(this.user_id);
Edit 3
constructor classone
public ClassOne(){ JButton btn = new JButton("Open"); btn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(!winList.contains(room_jid)){ new ClassTwo(room_jid,....); winList.add(room_jid); } } }); }
Harry joy
source share