Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

QUEZON CITY UNIVERSITY

COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

CC103 – INTERMEDIATE PRORGRAMMING


Activity #2 - FINALS
NAME: SCORE PERCENTAGE

STUDENT NO:
YEAR/SECTION
DATE:

Activity Title: Simple Login Form

Login Screen
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

After Login is Validated

Codes:
Log In Controller
package com.login.loginfinal;

import io.github.palexdev.materialfx.controls.MFXButton;
import io.github.palexdev.materialfx.controls.MFXPasswordField;
import io.github.palexdev.materialfx.controls.MFXTextField;
import javafx.animation.TranslateTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

import java.io.IOException;
import java.sql.*;

public class logInControl {


@FXML
private BorderPane logInBorderPane;
@FXML
private AnchorPane banner;
@FXML
private AnchorPane signInPane;
@FXML
private MFXButton signUpButton;
@FXML
private MFXButton logInButton;
@FXML
private MFXPasswordField passWord;
@FXML
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

private MFXTextField userName;


private Stage stage;
private Scene scene;
private Parent root;
static String uName;

public void dashBoard() throws IOException {


FXMLLoader loader = new FXMLLoader(getClass().getResource("/com/login/loginfinal/Fxml/dashBoard.fxml"));
root = loader.load();
dashBoardController dashBoardController = loader.getController();
dashBoardController.setUserWelcome(uName);
stage = (Stage) userName.getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.show();
}

public void checkLogin() {


String userNameValue = userName.getText();
String passWordValue = passWord.getText();
String userNameDB = "root", passWordDB = "";

try(Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/account", userNameDB, passWordDB);


PreparedStatement preparedStatement = conn.prepareStatement("SELECT * FROM activity_login WHERE userName = ?
AND userPassword = ?")) {
preparedStatement.setString(1, userNameValue);
preparedStatement.setString(2, passWordValue);
ResultSet resultSet = preparedStatement.executeQuery();

if (resultSet.next()) {
uName = userNameValue;
dashBoard();
} else {
TranslateTransition translateTransition = new TranslateTransition();
translateTransition.setDuration(javafx.util.Duration.seconds(0.5));
translateTransition.setNode(signInPane);
translateTransition.setToX(0);
translateTransition.play();
}

} catch (SQLException e) {
e.printStackTrace();

} catch (IOException e) {
throw new RuntimeException(e);
}
}

public void initialize() {


logInButton.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) {
checkLogin();
}
});passWord.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) {
checkLogin();
}
});userName.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) {
checkLogin();
}
});
}
}
QUEZON CITY UNIVERSITY
COLLEGE OF COMPUTER SCIENCE AND INFORMATION TECHNOLOGY

Dash Board Controller:


package com.login.loginfinal;

import javafx.fxml.FXML;
import javafx.scene.control.Label;

public class dashBoardController {

@FXML
private Label userWelcome;

public void setUserWelcome(String uName) {


userWelcome.setText("Welcome " + uName);
}
}

App
package com.login.loginfinal;

import io.github.palexdev.materialfx.css.themes.MFXThemeManager;
import io.github.palexdev.materialfx.css.themes.Themes;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class app extends Application {


@Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("/com/login/loginfinal/Fxml/logInWindow.fxml"));
Scene scene = new Scene(root);
stage.setTitle("Login");
MFXThemeManager.addOn(scene, Themes.DEFAULT, Themes.LEGACY);
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {


launch();
}
}

You might also like