0
我正在爲我的java服務器程序製作GUI,但是當我啓動它時,程序顯示白色的JFrame並且不會將組件加載到框架中。 這裏有代碼:使用jframe的java服務器
public ServerFrame() throws SQLException, ClassNotFoundException, IOException {
initComponents();
server = new ServerSocket(4444);
textList.setText("Waiting for client to connect...");
SimpleDataSource.init("database.properties");
net = new Network();
}
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable(){
@Override
public void run(){
ServerFrame sf;
try{
sf = new ServerFrame();
sf.setVisible(true);
s = server.accept();
InetAddress clientAddress = s.getInetAddress();
textList.setText("Incoming connection from: " + clientAddress.getHostName() + "[" + clientAddress.getHostAddress() + "]\n");
ServiceClass service = new ServiceClass(s,net);
Thread t = new Thread(service);
t.start();
}catch (SQLException | ClassNotFoundException | IOException ex){
Logger.getLogger(ServerFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
當程序啓動它不顯示我部件爲框架,因爲它等待客戶端連接。當客戶端連接它顯示正確的所有組件..如何顯示所有組件沒有客戶端連接?
感謝