I tried hiding a window on closing by
setDefaultCloseOperation(HIDE_ON_CLOSE);
.
But when I respawn the window by using
setVisible(true)
the window appears with size 0, and none of the components are visible. Why does this happen and what could be the solution?
This is the code for MyClient class and ListenServerOpenWindow class in which i have changed the visibility of the ChatWindow which is another class
public class MyClient extends WindowAdapter implements ActionListener
{
**********
MyClient(String name)throws IOException
{
windowsNames = new String[10];
c= new ChatWindow[10];
count =0; found =false;
********************
ListenServerOpenWindow m=new ListenServerOpenWindow(name,din,dout);
Thread t=new Thread(m);
t.start(); t.setName("Listening to Server for Request to Open Chat Window");
}
public void actionPerformed(ActionEvent e){
try
{
if(e.getSource()==button){
System.out.println(list1+"test");
str=(String)list1.getSelectedValue();
dout3.writeUTF(str);
found =false;
for(i=0;i<windowsnames.length;i++)>
{
if(windowsNames[i]!=null)
if(windowsNames[i].equalsIgnoreCase(str)&&windowsNames[i]!=null)
{
found=true; break;
}
}
if(found)
{
c[i].setVisible(true);
}
else
{
windowsNames[count]=str;
c[count++]= new ChatWindow(name,str,din,dout);
}
}
}catch(Exception ex){ex.printStackTrace();}
}
And the ListenServerOpenWindow class
class ListenServerOpenWindow implements Runnable
{
Socket s,s3;String chatwith,name; ChatWindow[] c;String[] windowsNames;
DataInputStream din;DataOutputStream dout; int count; boolean found; int i;
ListenServerOpenWindow(String name,DataInputStream din,DataOutputStream dout)
{
this.din = din;
this.dout= dout;
this.name=name;
this.s=MyClient.s;
this.s3 = MyClient.s3;
c=new ChatWindow[10];
windowsNames = new String[10];
count =0;found =false;
}
public void run()
{
try
{
while(true)
{
DataInputStream d = new DataInputStream(s3.getInputStream());
String cmd = d.readUTF();
if(cmd.length()>9)
{
chatwith = cmd.substring(10);
if(cmd.substring(0,10).equalsIgnoreCase("openwindow"))
{
found =false;
for(i=0;i<windowsnames.length;i++)>
{
if(windowsNames[i]!=null)
if(windowsNames[i].equalsIgnoreCase(chatwith))
{
found=true; break;
}
}
if(found)
{
c[i].setVisible(true);
}
else
{
windowsNames[count]=chatwith;
c[count++]= new ChatWindow(name,chatwith,din,dout);
}
}
}
}
}
catch(Exception e){e.printStackTrace();}
}
}
I have used
setDefaultCloseOperation(HIDE_ON_CLOSE)
in the constructor of the ChatWindow class which extends JFrame class
On respawning the chatwindow, none of the components are shown