Added GUI backbone (login and redirect to main stage)
This commit is contained in:
22
src/GUI/GUIController.java
Normal file
22
src/GUI/GUIController.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package GUI;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Label;
|
||||
|
||||
public class GUIController {
|
||||
int pressed;
|
||||
|
||||
//put @FXML to let the fxml file know that it can use this label,
|
||||
// ind of the same as with @Test in jUnit tests
|
||||
@FXML
|
||||
private Label txtLabel;
|
||||
|
||||
public void incrementLabel(ActionEvent event) throws Exception {
|
||||
// System.out.println("pressed button");
|
||||
pressed++;
|
||||
String labeltext = "Button pressed " + pressed + " times!";
|
||||
//set the text of the label to the string above
|
||||
txtLabel.setText(labeltext);
|
||||
}
|
||||
}
|
||||
23
src/GUI/GUIMain.fxml
Normal file
23
src/GUI/GUIMain.fxml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.GUIController">
|
||||
<children>
|
||||
<Label fx:id="txtLabel" layoutX="306.0" layoutY="248.0" text="Button pressed 0 times!">
|
||||
<font>
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button layoutX="362.0" layoutY="323.0" mnemonicParsing="false" onAction="#incrementLabel" text="Click me!">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
29
src/GUI/GUIMain.java
Normal file
29
src/GUI/GUIMain.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package GUI;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class GUIMain extends Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
//link fxml file
|
||||
Parent root = FXMLLoader.load(getClass().getResource("Login.fxml"));
|
||||
//set the scene
|
||||
Scene scene = new Scene(root, 400, 400);
|
||||
//link the stylesheet with the scene
|
||||
scene.getStylesheets().add(getClass().getResource("LoginStyle.css").toExternalForm());
|
||||
|
||||
//show the stagw
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("login");
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
3
src/GUI/GUIStyle.css
Normal file
3
src/GUI/GUIStyle.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.root {
|
||||
-fx-background-color: #eef9ee;
|
||||
}
|
||||
21
src/GUI/Login.fxml
Normal file
21
src/GUI/Login.fxml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<AnchorPane prefHeight="400.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.LoginController">
|
||||
<children>
|
||||
<TextField fx:id="usertext" layoutX="126.0" layoutY="182.0" promptText="Username" />
|
||||
<PasswordField fx:id="passwordField" layoutX="126.0" layoutY="244.0" promptText="Password" />
|
||||
<Button fx:id="loginbutton" layoutX="177.0" layoutY="317.0" mnemonicParsing="false" onAction="#Login" text="Login" />
|
||||
<Label fx:id="statustext" alignment="CENTER" layoutX="126.0" layoutY="91.0" textAlignment="CENTER" wrapText="true">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
63
src/GUI/LoginController.java
Normal file
63
src/GUI/LoginController.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package GUI;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.PasswordField;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
|
||||
public class LoginController {
|
||||
|
||||
//set labels and textfields, with the @FXML line to let the fxml file know it can use these
|
||||
@FXML
|
||||
private Label statustext;
|
||||
|
||||
@FXML
|
||||
private TextField usertext;
|
||||
|
||||
@FXML
|
||||
private PasswordField passwordField;
|
||||
|
||||
@FXML
|
||||
private Button loginbutton;
|
||||
|
||||
public void Login(ActionEvent event) throws Exception {
|
||||
//if the entered username and password are correct
|
||||
if (usertext.getText().equals("user") && passwordField.getText().equals("pass")) {
|
||||
//display green login succes message
|
||||
statustext.setText("Login success!");
|
||||
statustext.setTextFill(Color.GREEN);
|
||||
//and open next window
|
||||
openMainWindow();
|
||||
|
||||
} else {
|
||||
//else display red login failed message
|
||||
statustext.setText("Login failed! try again!");
|
||||
statustext.setTextFill(Color.RED);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void openMainWindow() throws Exception {
|
||||
//basically the same thing as in the main class: open a new stage
|
||||
Stage primaryStage = new Stage();
|
||||
//link fxml file
|
||||
Parent root = FXMLLoader.load(getClass().getResource("GUIMain.fxml"));
|
||||
//set the scene
|
||||
Scene scene = new Scene(root, 800, 600);
|
||||
//link the stylesheet with the scene
|
||||
scene.getStylesheets().add(getClass().getResource("GUIStyle.css").toExternalForm());
|
||||
|
||||
//show the stage
|
||||
primaryStage.setScene(scene);
|
||||
primaryStage.setTitle("oop project group 43");
|
||||
primaryStage.show();
|
||||
}
|
||||
}
|
||||
6
src/GUI/LoginStyle.css
Normal file
6
src/GUI/LoginStyle.css
Normal file
@@ -0,0 +1,6 @@
|
||||
.root {
|
||||
-fx-background-color: #91daff;
|
||||
}
|
||||
#usertext {
|
||||
-fx-text-fill: #670eed;
|
||||
}
|
||||
Reference in New Issue
Block a user