即时尝试显示服务器状态绿色处于关闭状态。不过,我似乎无法使小程序改变颜色!无法获取小应用程序上的服务器状态
@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