From 4e1b20e5db70c8b5dd16024fbd03415f9856cadd Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sat, 25 Apr 2020 19:50:29 +0200 Subject: [PATCH] Display IP address in EngineServer titlebar --- .../java/org/petero/engineserver/MainWindow.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/EngineServer/src/main/java/org/petero/engineserver/MainWindow.java b/EngineServer/src/main/java/org/petero/engineserver/MainWindow.java index ddf21a5..26550e4 100644 --- a/EngineServer/src/main/java/org/petero/engineserver/MainWindow.java +++ b/EngineServer/src/main/java/org/petero/engineserver/MainWindow.java @@ -27,6 +27,8 @@ import java.awt.event.FocusEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; +import java.net.InetAddress; +import java.net.UnknownHostException; import javax.swing.JButton; import javax.swing.JCheckBox; @@ -65,7 +67,14 @@ public class MainWindow { arguments = new JTextField[numEngines]; Container pane = frame.getContentPane(); - frame.setTitle("Chess Engine Server"); + String title = "Chess Engine Server"; + try { + InetAddress ip = InetAddress.getLocalHost(); + String addr = ip.getHostAddress(); + if (!"127.0.0.1".equals(addr)) + title += " : IP = " + addr; + } catch (UnknownHostException ignore) { } + frame.setTitle(title); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent event) { @@ -191,7 +200,7 @@ public class MainWindow { private void portChanged(int engineNo) { EngineConfig config = configs[engineNo]; try { - int p = Integer.valueOf(port[engineNo].getText().trim()); + int p = Integer.parseInt(port[engineNo].getText().trim()); if (p >= 1024 && p < 65536 && p != config.port) { config.port = p; server.configChanged(engineNo);