ADD::Added GUI for the registering

added a window to the sign up button, registering still gives an exception?
This commit is contained in:
Sem van der Hoeven
2019-03-16 18:37:23 +01:00
parent ad4e49f65c
commit 592015b1cd
8 changed files with 159 additions and 23 deletions

View File

@@ -37,24 +37,11 @@ public class Application extends javafx.application.Application {
public void start(Stage primaryStage) throws Exception {
fxmlLoader.setLocation(this.getClass().getClassLoader().getResource("fxml/sample.fxml"));
// fxmlLoader.setLocation(
// this.getClass().getClassLoader().getResource("fxml/dashboard.fxml")
// );
rootNode = fxmlLoader.load();
// rootNode = FXMLLoader.load(
// this.getClass().getClassLoader().getResource("fxml/sample.fxml")
// );
primaryStage.setTitle("GoGreen");
Scene scene = new Scene(rootNode);
// scene.getStylesheets().add(
// getClass().getResource("stylesheets/dashboardStyle.css").toExternalForm()
// );
primaryStage.setScene(scene);
primaryStage.show();
}

View File

@@ -0,0 +1,81 @@
package greenify.client.controller;
import greenify.client.rest.UserService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
public class RegisterWindowController {
@Autowired
UserService userService;
@FXML
private TextField userNameText;
@FXML
private PasswordField passwordField;
@FXML
private PasswordField passwordField2;
@FXML
private Button signupButton;
/**
* signs the user up.
* @param event the click of the signup button
*/
@FXML
public void handleSignUpButton(ActionEvent event) {
// System.out.println("pressed sign up button!");
//set the window to the current window (for displaying the alerts)
Window owner = signupButton.getScene().getWindow();
//check if the username field is empty
if (userNameText.getText().isEmpty()) {
//if so, display an alert
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"Please enter a username!");
return;
}
// else {
// System.out.println("username is " + userNameText.getText());
// }
//check if the password field is empty
if (passwordField.getText().isEmpty()) {
//if so, display an alert
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!",
"Please enter a password!");
return;
}
// else {
// System.out.println("password is " + passwordField.getText());
// }
//check if the two password fields are equal
if (!passwordField.getText().equals(passwordField2.getText())) {
//if not, display an alert
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Password Error!",
"Please make sure the passwords entered are the same!");
return;
}
// else {
// System.out.println("registered user with username:"
// + userNameText.getText()
// + ", and password:" + passwordField.getText());
// }
userService.registerUser(userNameText.getText(), passwordField.getText());
//close the register window after the user has entered all the credentials
Stage current = (Stage) owner;
current.close();
}
}

View File

@@ -81,6 +81,9 @@ public class UserController {
// app_stage.setScene(scene);
// app_stage.setFullScreen(true);
// app_stage.show();
Stage current = (Stage) owner;
current.close();
openDashboard();
}
@@ -128,4 +131,19 @@ public class UserController {
}
}
//method to open the register window
public void handleRegisterButtonAction(ActionEvent event) throws Exception{
//load the fxml file
Parent registerWindow = FXMLLoader.load (
this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml")
);
//make the window use the scene
Scene registerscene = new Scene(registerWindow);
Stage registerStage = new Stage();
//open the window
registerStage.setScene(registerscene);
registerStage.setTitle("Enter register credentials");
registerStage.show();
}
}

View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.image.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane prefHeight="300.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
<children>
<ImageView fitHeight="312.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../registerBackground.png" />
</image>
</ImageView>
<Text fill="#00650d" layoutX="103.0" layoutY="42.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Register">
<font>
<Font size="26.0" />
</font>
</Text>
<TextField fx:id="userNameText" layoutX="69.0" layoutY="94.0" promptText="Username">
<font>
<Font size="13.0" />
</font>
</TextField>
<Button fx:id="signupButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
<font>
<Font name="Corbel Bold" size="14.0" />
</font>
</Button>
<PasswordField fx:id="passwordField" layoutX="69.0" layoutY="138.0" promptText="Password">
<font>
<Font size="13.0" />
</font>
</PasswordField>
<PasswordField fx:id="passwordField2" layoutX="69.0" layoutY="182.0" promptText="Re-enter password">
<font>
<Font size="13.0" />
</font>
</PasswordField>
</children>
</AnchorPane>

View File

@@ -34,7 +34,7 @@
</font>
</Button>
</children></AnchorPane>
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0">
<AnchorPane fx:id="activitiesPane" layoutX="214.0" prefHeight="603.0" prefWidth="711.0" visible="false">
<children>
<Text layoutX="101.0" layoutY="74.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Available Activities" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">
<font>
@@ -55,7 +55,7 @@
</font>
</Text>
</children></AnchorPane>
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0" visible="false">
<AnchorPane fx:id="dashboardPane" layoutX="215.0" prefHeight="603.0" prefWidth="711.0">
<children>
<HBox layoutX="97.0" layoutY="124.0" prefHeight="100.0" prefWidth="200.0" />
<Label fx:id="welcomebacktext" layoutX="69.0" layoutY="53.0" text="Welcome back user!" AnchorPane.leftAnchor="60.0" AnchorPane.topAnchor="40.0">

View File

@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Hyperlink?>
<?import javafx.scene.control.PasswordField?>
@@ -10,7 +15,7 @@
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<AnchorPane fx:controller="greenify.client.controller.UserController" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="574.0" prefWidth="934.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.UserController">
<children>
<ImageView fitHeight="574.0" fitWidth="943.0" layoutX="-1.0" pickOnBounds="true">
<image>
@@ -21,8 +26,8 @@
<Font name="Californian FB" size="72.0" />
</font>
</Text>
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" onAction="#handleLoginButtonAction"/>
<Button fx:id="signupButton" layoutX="49.0" layoutY="52.0" mnemonicParsing="false" prefHeight="6.0" prefWidth="61.0" text="Sign UP"/>
<Button fx:id="loginButton" layoutX="419.0" layoutY="274.0" mnemonicParsing="false" onAction="#handleLoginButtonAction" prefHeight="26.0" prefWidth="96.0" text="Login" textAlignment="CENTER" />
<Button fx:id="signupButton" layoutX="49.0" layoutY="52.0" mnemonicParsing="false" onAction="#handleRegisterButtonAction" prefHeight="6.0" prefWidth="61.0" text="Sign up!" />
<PasswordField fx:id="passwordField" layoutX="318.0" layoutY="210.0" prefHeight="42.0" prefWidth="303.0" promptText="Password" />
<Hyperlink layoutX="392.0" layoutY="308.0" prefHeight="42.0" prefWidth="173.0" text="Forgot Password?" textAlignment="CENTER" textFill="WHITE" textOverrun="LEADING_WORD_ELLIPSIS">
<font>

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -1,5 +1,5 @@
.button {
-fx-border-width: 0px 0px 1px 0px;
-fx-border-color: #f9f9f9;
-fx-border-radius: 0%;
}
/*.button {*/
/*-fx-border-width: 0px 0px 1px 0px;*/
/*-fx-border-color: #f9f9f9;*/
/*-fx-border-radius: 0%;*/
/*}*/