client gui + headless server
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
plugins {
|
plugins {
|
||||||
// Apply the application plugin to add support for building a CLI application in Java.
|
// Apply the application plugin to add support for building a CLI application in Java.
|
||||||
id 'application'
|
id 'application'
|
||||||
|
id 'org.openjfx.javafxplugin' version '0.1.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@@ -32,9 +33,13 @@ java {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
javafx {
|
||||||
|
modules = ['javafx.graphics', 'javafx.controls', 'javafx.fxml' ]
|
||||||
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
// Define the main class for the application.
|
// Define the main class for the application.
|
||||||
mainClass = 'ChatApp'
|
mainClass = 'client.ClientGui'
|
||||||
}
|
}
|
||||||
|
|
||||||
run {
|
run {
|
||||||
@@ -48,7 +53,7 @@ tasks.named('test') {
|
|||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("server", JavaExec){
|
tasks.register("admin", JavaExec){
|
||||||
group = "ChatAppConsole"
|
group = "ChatAppConsole"
|
||||||
description = "Runs the server + the admin client"
|
description = "Runs the server + the admin client"
|
||||||
mainClass.set("ChatApp")
|
mainClass.set("ChatApp")
|
||||||
@@ -56,6 +61,14 @@ tasks.register("server", JavaExec){
|
|||||||
standardInput = System.in
|
standardInput = System.in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register("server", JavaExec){
|
||||||
|
group = "ChatAppConsole"
|
||||||
|
description = "Runs the headless server"
|
||||||
|
mainClass.set("ChatAppServer")
|
||||||
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
standardInput = System.in
|
||||||
|
}
|
||||||
|
|
||||||
tasks.register("client", JavaExec) {
|
tasks.register("client", JavaExec) {
|
||||||
group = "ChatAppConsole"
|
group = "ChatAppConsole"
|
||||||
description = "Runs the client"
|
description = "Runs the client"
|
||||||
|
|||||||
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRunningPort() {
|
||||||
|
return this.serverSocket.getLocalPort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user