added gui for server
This commit is contained in:
@@ -34,7 +34,7 @@ java {
|
|||||||
}
|
}
|
||||||
|
|
||||||
javafx {
|
javafx {
|
||||||
modules = ['javafx.graphics', 'javafx.controls', 'javafx.fxml' ]
|
modules = [ 'javafx.graphics', 'javafx.controls', 'javafx.fxml' ]
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
@@ -76,3 +76,10 @@ tasks.register("client", JavaExec) {
|
|||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
standardInput = System.in
|
standardInput = System.in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register("serverGUI", JavaExec) {
|
||||||
|
group = "ChatAppGUI"
|
||||||
|
description = "Runs a GUI for the server"
|
||||||
|
mainClass.set('server.ServerGUI')
|
||||||
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
|
}
|
||||||
35
ChatApp/app/src/main/java/network/IPAddressFinder.java
Normal file
35
ChatApp/app/src/main/java/network/IPAddressFinder.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package network;
|
||||||
|
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
public class IPAddressFinder {
|
||||||
|
public static String findIPAddress(){
|
||||||
|
try {
|
||||||
|
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
|
|
||||||
|
while (networkInterfaces.hasMoreElements()) {
|
||||||
|
NetworkInterface networkInterface = networkInterfaces.nextElement();
|
||||||
|
|
||||||
|
Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
|
||||||
|
|
||||||
|
while (inetAddresses.hasMoreElements()) {
|
||||||
|
InetAddress inetAddress = inetAddresses.nextElement();
|
||||||
|
|
||||||
|
if (!inetAddress.isLoopbackAddress()) {
|
||||||
|
String ip = inetAddress.getHostAddress();
|
||||||
|
|
||||||
|
if (ip.startsWith("192.168")) {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SocketException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "Not Found";
|
||||||
|
}
|
||||||
|
}
|
||||||
34
ChatApp/app/src/main/java/server/ServerGUI.java
Normal file
34
ChatApp/app/src/main/java/server/ServerGUI.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package server;
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import javafx.stage.Screen;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ServerGUI extends Application {
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws IOException {
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(ServerGUI.class.getResource("hello-view.fxml"));
|
||||||
|
Scene scene = new Scene(fxmlLoader.load(), 400, 240);
|
||||||
|
|
||||||
|
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
|
||||||
|
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
|
||||||
|
|
||||||
|
double xPos = screenWidth / 2 - scene.getWidth() / 2;
|
||||||
|
double yPos = screenHeight / 2 - scene.getHeight() / 2;
|
||||||
|
|
||||||
|
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
|
||||||
|
stage.setTitle("Server");
|
||||||
|
stage.setScene(scene);
|
||||||
|
stage.setX(xPos);
|
||||||
|
stage.setY(yPos);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
launch();
|
||||||
|
}
|
||||||
|
}
|
||||||
17
ChatApp/app/src/main/java/server/ServerGUIController.java
Normal file
17
ChatApp/app/src/main/java/server/ServerGUIController.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package server;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import network.IPAddressFinder;
|
||||||
|
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
|
public class ServerGUIController {
|
||||||
|
@FXML
|
||||||
|
private Label IPAddress;
|
||||||
|
|
||||||
|
public void initialize() throws UnknownHostException {
|
||||||
|
IPAddress.setText("IP Address: " + IPAddressFinder.findIPAddress());
|
||||||
|
IPAddress.getStyleClass().add("address");
|
||||||
|
}
|
||||||
|
}
|
||||||
10
ChatApp/app/src/main/resources/server/style.css
Normal file
10
ChatApp/app/src/main/resources/server/style.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
.root{
|
||||||
|
-fx-background-color: darkblue;
|
||||||
|
-fx-text-fill: blue;
|
||||||
|
-fx-font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.address {
|
||||||
|
-fx-text-fill: white;
|
||||||
|
-fx-font-size: 25px;
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# This file was generated by the Gradle 'init' task.
|
# This file was generated by the Gradle 'init' task.
|
||||||
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
# https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
|
||||||
|
|
||||||
org.gradle.configuration-cache=true
|
org.gradle.configuration-cache=false
|
||||||
org.gradle.console=plain
|
org.gradle.console=plain
|
||||||
org.gradle.logging.level=quiet
|
org.gradle.logging.level=quiet
|
||||||
Reference in New Issue
Block a user