Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sample.controller;
- import com.jfoenix.controls.JFXPasswordField;
- import com.jfoenix.controls.JFXTextField;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.input.MouseEvent;
- import javafx.stage.Stage;
- import javafx.stage.StageStyle;
- import sample.connection.Connector;
- import java.io.IOException;
- import java.net.URL;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ResourceBundle;
- public class LoginController implements Initializable {
- private Connection connection;
- private Statement statement;
- private ResultSet set;
- @FXML
- private JFXTextField tfUsername;
- @FXML
- private JFXPasswordField tfPassword;
- @Override
- public void initialize(URL location, ResourceBundle resources){
- }
- @FXML
- private void handleCancelButtonAction(MouseEvent event) {
- System.exit(0);
- }
- @FXML
- private void handleLoginButtonAction(MouseEvent event) throws SQLException {
- connection = Connector.getConnection();
- statement = connection.createStatement();
- StringBuilder query = new StringBuilder();
- query.append("SELECT * FROM Korisnici where username='").append(tfUsername.getText()).append("' ").append(
- "and ").append("password='").append(tfPassword.getText()).append("'");
- set = statement.executeQuery(query.toString());
- loadUserScreen();
- closeStage();
- if(set.first()){
- closeStage();
- loadUserScreen();
- }else {
- tfPassword.setText("");
- tfUsername.setText("");
- tfUsername.getStyleClass().add("wrong-credentials");
- tfPassword.getStyleClass().add("wrong-credentials");
- }
- }
- private void closeStage() {
- ((Stage) tfUsername.getScene().getWindow()).close();
- }
- public void loadUserScreen() {
- try {
- Parent parent = FXMLLoader.load(getClass().getResource("../View/user.fxml"));
- Stage stage = new Stage(StageStyle.DECORATED);
- stage.setTitle("Obracun puta");
- stage.setScene(new Scene(parent));
- stage.show();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- void loadAdminScreen() {
- try {
- Parent parent = FXMLLoader.load(getClass().getResource("../View/admin.fxml"));
- Stage stage = new Stage(StageStyle.DECORATED);
- stage.setTitle("Obračun poslovnih puteva - Admin Deo");
- stage.setScene(new Scene(parent));
- stage.show();
- }
- catch (IOException ex) {
- System.err.println("Error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement