ServerGui view

This commit is contained in:
Clément
2025-03-05 12:06:27 +01:00
parent 583505d93a
commit a83104d322
4 changed files with 51 additions and 6 deletions

View File

@@ -4,15 +4,17 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.stage.Screen;
import java.io.IOException;
import java.util.Objects;
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);
FXMLLoader loader = new FXMLLoader(getClass().getResource("/server/serverVue.fxml"));
Scene scene = new Scene(loader.load(), 400, 240);
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
@@ -21,6 +23,7 @@ public class ServerGUI extends Application {
double yPos = screenHeight / 2 - scene.getHeight() / 2;
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
stage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/liscord.png"))));
stage.setTitle("Server");
stage.setScene(scene);
stage.setX(xPos);

View File

@@ -1,17 +1,42 @@
package server;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import network.IPAddressFinder;
import java.net.SocketException;
import java.net.UnknownHostException;
public class ServerGUIController {
@FXML
private Label IPAddress;
@FXML
private Button toggleServerButton;
private Server server;
@FXML
public void initialize() throws UnknownHostException {
IPAddress.setText("IP Address: " + IPAddressFinder.findIPAddress());
IPAddress.getStyleClass().add("address");
}
@FXML
public void toggleServer() throws SocketException {
if(server == null){
toggleServerButton.setDisable(true);
server = new Server(6665);
toggleServerButton.setDisable(false);
toggleServerButton.setText("Stop Server");
System.out.println("Server started on port 6665");
} else {
toggleServerButton.setDisable(true);
server.close();
server = null;
toggleServerButton.setDisable(false);
toggleServerButton.setText("Start Server");
}
}
}

View File

@@ -9,6 +9,6 @@
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<Label fx:id="IPAddress" />
<Button text="Enable Server" />
<Label fx:id="IPAddress" styleClass="address" />
<Button text="Start Server" onAction="#toggleServer" fx:id="toggleServerButton" styleClass="toggle-button"/>
</VBox>

View File

@@ -8,3 +8,20 @@
-fx-text-fill: white;
-fx-font-size: 25px;
}
.toggle-button {
-fx-background-color: darkblue;
-fx-text-fill: white;
-fx-font-size: 20px;
-fx-padding: 10px;
-fx-border-width: 2px;
-fx-border-color: white;
-fx-cursor: hand;
-fx-border-radius: 5;
}
.toggle-button:hover {
-fx-background-color: white;
-fx-text-fill: darkblue;
transition: -fx-background-color 0.3s, -fx-text-fill 0.3s;
}