ServerGui view
This commit is contained in:
@@ -4,15 +4,17 @@ import javafx.application.Application;
|
|||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import javafx.stage.Screen;
|
import javafx.stage.Screen;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ServerGUI extends Application {
|
public class ServerGUI extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(ServerGUI.class.getResource("hello-view.fxml"));
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/server/serverVue.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 400, 240);
|
Scene scene = new Scene(loader.load(), 400, 240);
|
||||||
|
|
||||||
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
|
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
|
||||||
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
|
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
|
||||||
@@ -21,6 +23,7 @@ public class ServerGUI extends Application {
|
|||||||
double yPos = screenHeight / 2 - scene.getHeight() / 2;
|
double yPos = screenHeight / 2 - scene.getHeight() / 2;
|
||||||
|
|
||||||
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
|
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
|
||||||
|
stage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResourceAsStream("/liscord.png"))));
|
||||||
stage.setTitle("Server");
|
stage.setTitle("Server");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
stage.setX(xPos);
|
stage.setX(xPos);
|
||||||
|
|||||||
@@ -1,17 +1,42 @@
|
|||||||
package server;
|
package server;
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import network.IPAddressFinder;
|
import network.IPAddressFinder;
|
||||||
|
|
||||||
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public class ServerGUIController {
|
public class ServerGUIController {
|
||||||
@FXML
|
@FXML
|
||||||
private Label IPAddress;
|
private Label IPAddress;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button toggleServerButton;
|
||||||
|
|
||||||
|
private Server server;
|
||||||
|
|
||||||
|
@FXML
|
||||||
public void initialize() throws UnknownHostException {
|
public void initialize() throws UnknownHostException {
|
||||||
IPAddress.setText("IP Address: " + IPAddressFinder.findIPAddress());
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,6 @@
|
|||||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||||
</padding>
|
</padding>
|
||||||
|
|
||||||
<Label fx:id="IPAddress" />
|
<Label fx:id="IPAddress" styleClass="address" />
|
||||||
<Button text="Enable Server" />
|
<Button text="Start Server" onAction="#toggleServer" fx:id="toggleServerButton" styleClass="toggle-button"/>
|
||||||
</VBox>
|
</VBox>
|
||||||
@@ -8,3 +8,20 @@
|
|||||||
-fx-text-fill: white;
|
-fx-text-fill: white;
|
||||||
-fx-font-size: 25px;
|
-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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user