client gui + headless server

This commit is contained in:
2025-03-04 16:07:35 +01:00
parent e536a45266
commit 76da347fb9
4 changed files with 61 additions and 2 deletions

View File

@@ -0,0 +1,15 @@
import java.net.SocketException;
import server.Server;
public class ChatAppServer {
public static void main(String[] args) {
// run ./gradlew server --args="port" to launch the server with a specific port
try {
Server server = new Server(args.length > 0 ? Integer.parseInt(args[0]) : 0);
System.out.println("Server running on port " + server.getRunningPort() + "!");
} catch (SocketException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,28 @@
package client;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ClientGui extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("JavaFX with Gradle");
Label label = new Label("Hello, JavaFX!");
StackPane root = new StackPane(label);
Scene scene = new Scene(root, 640, 480);
primaryStage.setScene(scene);
primaryStage.show();
}
}

View File

@@ -149,4 +149,7 @@ public class Server implements PacketHandler {
return false;
}
public int getRunningPort() {
return this.serverSocket.getLocalPort();
}
}