Display IP address in EngineServer titlebar

This commit is contained in:
Peter Osterlund 2020-04-25 19:50:29 +02:00
parent 795428992f
commit 4e1b20e5db

View File

@ -27,6 +27,8 @@ import java.awt.event.FocusEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
@ -65,7 +67,14 @@ public class MainWindow {
arguments = new JTextField[numEngines]; arguments = new JTextField[numEngines];
Container pane = frame.getContentPane(); 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() { frame.addWindowListener(new WindowAdapter() {
@Override @Override
public void windowClosing(WindowEvent event) { public void windowClosing(WindowEvent event) {
@ -191,7 +200,7 @@ public class MainWindow {
private void portChanged(int engineNo) { private void portChanged(int engineNo) {
EngineConfig config = configs[engineNo]; EngineConfig config = configs[engineNo];
try { 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) { if (p >= 1024 && p < 65536 && p != config.port) {
config.port = p; config.port = p;
server.configChanged(engineNo); server.configChanged(engineNo);