3
我正在使用Java远程桌面管理。当我单独运行服务器启动器主类时它工作正常。但是当我从一个按钮的动作事件调用该类时,该框架会冻结并显示一个黑色屏幕..这里是代码。任何帮助?Java远程桌面管理
import java.awt.BorderLayout;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class ServerInitiator {
//Main server frame
private JFrame frame = new JFrame();
//JDesktopPane represents the main container that will contain all
//connected clients' screens
private JDesktopPane desktop = new JDesktopPane();
public static void main(String args[]){
String port = JOptionPane.showInputDialog("Please enter listening port");
new ServerInitiator().initialize(Integer.parseInt(port));
}
public void initialize(int port){
try {
ServerSocket sc = new ServerSocket(port);
//Show Server GUI
drawGUI();
//Listen to server port and accept clients connections
while(true){
Socket client = sc.accept();
System.out.println("New client Connected to the server");
//Per each client create a ClientHandler
new ClientHandler(client,desktop);
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
/*
* Draws the main server GUI
*/
public void drawGUI(){
frame.add(desktop,BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Show the frame in a maximized state
frame.setExtendedState(frame.getExtendedState()|JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
}
}
完美。 Swingworkers正是我需要的笏。拯救了我的生活@MadProgrammer – ustaad