服务器GUI隐藏

时间:2015-08-25 15:41:45

标签: java sockets client-server

当我启动我的服务器和客户端应用程序时,不会发生任何错误,并且除了我的服务器GUI没有显示外,它们都按预期运行。它虽然运作正常。可能导致问题的原因是什么?我将不胜感激任何帮助!

注意:我的服务器gui运行正常,直到我尝试实现线程

编辑:我添加了各种System.out.println(jtaResults.getText());整个构造函数和文本区域都有正确的数据,尽管GUI没有出现。

Edit2:在public void run中,程序执行第ServerApp gui = new ServerApp();行,但从不执行gui.setVisible(true); 我如何强制它将gui设置为可见?

public class ServerApp extends javax.swing.JFrame {

int clientNum = 1;
Date dateobj = new Date();
 DateFormat df = new SimpleDateFormat("EEE MMM d HH:mm:ss z YYYY" );

public ServerApp() {

    initComponents();


             try{
                 jtaResults.setText("Server started at " + df.toString() );
                 ServerSocket serverSocket = new ServerSocket(8090,100);
                 while(true){
                     Socket socket = serverSocket.accept();

                     System.out.println("new socket accepted");
                 ProcessClient client = new ProcessClient(socket, clientNum);

                 System.out.println("new client created");


                 Thread t = new Thread(client);
                 System.out.println("new thread created");
                 t.start();
                 System.out.println("tread started");
                 client.createMessage();
                 System.out.println("client create message invoked");
                 jtaResults.append(client.acceptMessage());
                 System.out.println("accept message appended to server screen");
                 clientNum++;
                // client.createStreams();
                 }
             }catch(Exception e){
                 System.out.println("Multiple connections failed: " + e);
             }
        }

public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            ServerApp gui = new ServerApp();
            gui.setVisible(true);
        }
    });

}       

init组件

private void initComponents() {

    jScrollPane3 = new javax.swing.JScrollPane();
    jScrollPane4 = new javax.swing.JScrollPane();
    jtaResults = new javax.swing.JTextArea();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jtaResults.setEditable(false);
    jtaResults.setColumns(20);
    jtaResults.setRows(5);
    jtaResults.setText("Server started at: ");
    jScrollPane4.setViewportView(jtaResults);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 404, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
    );

    pack();
}

0 个答案:

没有答案