I am making a client server application in which the server code is executed by a JFrame This is my server code when I call Show method from main method of MyServer class then it is working but when I call it from Key Event of Jframe then it is not showing the another Jframe. Please help.
public class MyServer
public void Show() throws IOException {
ServerSocket ss = new ServerSocket(6666);
new IPScanning().dispose();
int count = 0;
while (true) {
Socket s = null;
try {
s = ss.accept();
SocketThread socketThread = new SocketThread(s, count);
socketThread.start();
} catch (Exception e) {
ss.close();
s.close();
System.out.println(e);
} finally {
count++;
}
}
}
class SocketThread extends Thread {
public void run() {
try {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
ShowTable.INSTANCE.showdata(count, host, ip, username, os_name, os_arch, pro_detail, Mac_add, disk_size, max_memory);
}
});
} catch (Exception e) {
System.out.println("Server Problem");
System.out.println(e);
}
}
}
}`
This is my Key Event
private void jStartActionPerformed(java.awt.event.ActionEvent evt) {
MyServer ms=new MyServer();
try {
ms.Show();
} catch (IOException ex) {
System.out.println(ex);
}
}
Code of another JFrame calling through SocketThread class.
public enum ShowTable{
INSTANCE;
private JFrame f = new JFrame();
private JTable jt = new JTable(new DefaultTableModel());
private DefaultTableModel model = (DefaultTableModel) jt.getModel();
private ShowTable() {
jt.setBounds(30, 40, 200, 300);
jt.setFocusable(false);
jt.setRowSelectionAllowed(false);
JScrollPane sp = new JScrollPane(jt);
f.add(sp);
f.setSize(1300, 600);
}
public void showdata(int count,String host,String ip,String username,String os_name,String os_arch,String pro_detail,String Mac_add,float disk_size,float max_memory){
f.setVisible(true);
}
}