太糟糕了,我不得不硬重启(按住电源按钮),它甚至没有给我调试的时间,所以如果我在这里没有得到答案,我基本上就完蛋了。我知道它是服务器端的(当我不运行客户端时会发生这种情况,但如果我这样做也会发生)。
这是服务器代码:
package cypri.games.cybatarserver;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class CybatarServer extends JFrame implements Runnable{
String verNum = "0.0.0";
JScrollPane jsp;
JTextArea mainText;
boolean stopServer = false;
boolean waitForPlayers = true;
Vector<Player> playersConnected;
byte playerID = -1;
public CybatarServer(){
playersConnected = new Vector<Player>();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 400, 100);
this.setTitle("Cybatar Server " + verNum);
mainText = new JTextArea(50, 10);
mainText.setText("Welcome to CybatarServer "+ verNum + "!\n");
mainText.setEditable(false);
jsp = new JScrollPane(mainText);
this.add(jsp);
this.setVisible(true);
}
public static void main(String[] args){
CybatarServer cyserv = new CybatarServer();
cyserv.run();
}
@Override
public void run() {
try {
final ServerSocket serverSocket = new ServerSocket(44444);
while(!stopServer){
if(waitForPlayers){
new Thread(new Runnable() {
public void run() {
Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
playerID++;
new PlayerThread(playerID, playersConnected, mainText, playerID, clientSocket).start();
mainText.append("Player " + playerID + " connected!");
}
}).start();
}
else{
for(int i = 0; i < playersConnected.size(); i++){
playersConnected.get(i).update();
}
}
Thread.yield();
}
} catch (Exception e) { e.printStackTrace(); }
}
}
这里有什么东西会导致我的电脑完全死机吗?如果是这样,我该如何解决?