即時嘗試顯示服務器狀態綠色處於關閉狀態。不過,我似乎無法使小程序改變顏色!無法獲取小應用程序上的服務器狀態
@SuppressWarnings("serial")
public class MinecraftPinger extends Applet {
boolean O = true;
public void Pinger() throws IOException, InterruptedException {
while (true) {
Socket socket = SocketFactory.getDefault().createSocket();
try {
socket.setSoTimeout(5000);
socket.connect(new InetSocketAddress("192.148.1.1", 25565));
socket.close();
System.out.println(O);
Thread.sleep(600000);
repaint();
} catch (ConnectException e) {
O = false;
repaint();
Thread.sleep(600000);
}
}
}//ends Pinger
public void paint(Graphics g) {
try {
if (O == true) {
setSize(100, 25);
setBackground(Color.GREEN);
} else {
setSize(100, 25);
setBackground(Color.RED);
}
} catch (Exception ex) {
System.out.println("Fail!");
}
}
}
請在這裏發表您的代碼;不在第三方網站上。 –
我不認爲你的計算機的IP地址是'192.148.1.1',我想你混淆了你的計算機IP與路由器 –
,IP是假的,使小程序紅,但小程序不會變紅 – superhamster