Login page
This commit is contained in:
@@ -18,8 +18,8 @@ public class ClientGui extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/client/clientLoading.fxml"));
|
||||
Scene scene = new Scene(loader.load(), 800, 600);
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/client/clientLogin.fxml"));
|
||||
Scene scene = new Scene(loader.load(), 400, 240);
|
||||
|
||||
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
|
||||
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
|
||||
|
||||
25
ChatApp/app/src/main/java/client/ClientLogin.java
Normal file
25
ChatApp/app/src/main/java/client/ClientLogin.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package client;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.stage.Stage;
|
||||
import client.ClientGui;
|
||||
import java.io.IOException;
|
||||
|
||||
import static utilities.FxUtilities.centerStage;
|
||||
|
||||
public class ClientLogin {
|
||||
@FXML
|
||||
public TextField usernameField;
|
||||
|
||||
@FXML
|
||||
private void login() throws IOException {
|
||||
var loader = new FXMLLoader(getClass().getResource("/client/clientLoading.fxml"));
|
||||
loader.load();
|
||||
Stage stage = (Stage) usernameField.getScene().getWindow();
|
||||
stage.setScene(new Scene(loader.getRoot(), 800, 600));
|
||||
centerStage(stage);
|
||||
}
|
||||
}
|
||||
17
ChatApp/app/src/main/java/utilities/FxUtilities.java
Normal file
17
ChatApp/app/src/main/java/utilities/FxUtilities.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package utilities;
|
||||
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class FxUtilities {
|
||||
public static void centerStage(Stage stage) {
|
||||
double screenWidth = Screen.getPrimary().getVisualBounds().getWidth();
|
||||
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
|
||||
|
||||
double xPos = screenWidth / 2 - stage.getWidth() / 2;
|
||||
double yPos = screenHeight / 2 - stage.getHeight() / 2;
|
||||
|
||||
stage.setX(xPos);
|
||||
stage.setY(yPos);
|
||||
}
|
||||
}
|
||||
33
ChatApp/app/src/main/resources/client/clientLogin.fxml
Normal file
33
ChatApp/app/src/main/resources/client/clientLogin.fxml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<?import javafx.geometry.Insets?>
|
||||
<GridPane xmlns="http://javafx.com/javafx"
|
||||
xmlns:fx="http://javafx.com/fxml"
|
||||
fx:controller="client.ClientLogin"
|
||||
prefHeight="400.0" prefWidth="600.0">
|
||||
|
||||
<VBox spacing="10.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||
<Label text="Enter your username"/>
|
||||
<TextField fx:id="usernameField"/>
|
||||
<Button text="Login" onAction="#login"/>
|
||||
</VBox>
|
||||
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
<ColumnConstraints halignment="CENTER"/>
|
||||
<ColumnConstraints hgrow="ALWAYS"/>
|
||||
</columnConstraints>
|
||||
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="ALWAYS"/>
|
||||
<RowConstraints valignment="CENTER"/>
|
||||
<RowConstraints vgrow="ALWAYS"/>
|
||||
</rowConstraints>
|
||||
|
||||
</GridPane>
|
||||
Reference in New Issue
Block a user