client gui + headless server
This commit is contained in:
15
ChatApp/app/src/main/java/ChatAppServer.java
Normal file
15
ChatApp/app/src/main/java/ChatAppServer.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
28
ChatApp/app/src/main/java/client/ClientGui.java
Normal file
28
ChatApp/app/src/main/java/client/ClientGui.java
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -149,4 +149,7 @@ public class Server implements PacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getRunningPort() {
|
||||
return this.serverSocket.getLocalPort();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user