Error creating login screen with Javafx

Asked

Viewed 467 times

2

Good evening guys, I’m wanting to implement a login screen with the following fields, but it does not appear the other fields, appears the user field and password

Forgot the login click here:________ Forgot password click here:________ Usuario:___________ Password:_____________

Students Botao(register)

Pofessores or employees Botao(register)

Follows an image for better understanding: inserir a descrição da imagem aqui

Follow the screen code:

    package Teste;

import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Group;
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.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class LoginApp extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Sitema de Gerenciamento Academico");
        AnchorPane pane = new AnchorPane();
        pane.setPrefSize(700, 400);
        TextField txLogin = new TextField();
        Scene scene = new Scene(pane);

        Group root = new Group();
        GridPane gridpane = new GridPane();
        gridpane.setPadding(new Insets(5)); 
        //gridpane.setHgap(10);
        //gridpane.setVgap(10);
        Label label = new Label("Esqueceu o login? Clique aqui para recuperá-lo. "
                + "Esqueceu a senha? Clique aqui para recuperá-la.");
        GridPane.setHalignment(label, HPos.CENTER);
        gridpane.add(label, 0, 0);
        root.getChildren().add(gridpane);        
        //stage.setScene(scene); 

        txLogin.setPromptText("Digite aqui seu login"); 
        PasswordField txSenha = new PasswordField(); 
        txSenha.setPromptText("Digite aqui sua senha");
        Button btEntrar = new Button("Entrar"); 
        Button btSair = new Button("Sair");
        pane.getChildren().addAll(txLogin, txSenha, btEntrar, btSair);

        stage.setScene(scene);  
        stage.show(); 

        txLogin.setLayoutX((pane.getWidth() - txLogin.getWidth()) / 2);
        txLogin.setLayoutY(50);
        txSenha.setLayoutX((pane.getWidth() - txSenha.getWidth()) / 2);
        txSenha.setLayoutY(100);
        btEntrar.setLayoutX(
        (pane.getWidth() - btEntrar.getWidth()) / 2);
        btEntrar.setLayoutY(150);
        btSair.setLayoutX((pane.getWidth() - btSair.getWidth()) / 2);
        btSair.setLayoutY(200);

        //pane.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 100% 100%, blue 0%, silver 100%);");   

    }

    public static void main(String[] args) {
        launch(args);
    }   
}

Some comments on the code was made to test and see that it worked as described above but did not work. I thank you for your help..

1 answer

1

I created a screen similar to the result you want with a Vbox and a Hbox. Follow the code:

TextField login = new TextField();
PasswordField senha = new PasswordField();
login.setPromptText("Usuário");
login.setPrefWidth(405);
senha.setPromptText("Senha");
senha.setPrefWidth(405);

Button entrar = new Button("Entrar");
entrar.setPrefWidth(405);
entrar.setPrefHeight(40);

Button cadastroProfessor = new Button("Professor ou funcionário?\nCadastre-se");
Button cadastroAluno = new Button("Aluno?\nCadastre-se");
cadastroProfessor.setPrefWidth(200);
cadastroAluno.setPrefWidth(200);
HBox opcoes = new HBox(5);
opcoes.getChildren().addAll(cadastroProfessor,cadastroAluno);

Hyperlink recuperarLogin = new Hyperlink("Esqueceu seu login? Clique aqui");
Hyperlink recuperarSenha = new Hyperlink("Esqueceu sua senha? Clique aqui");

VBox loginScene = new VBox(5);
loginScene.fillWidthProperty().setValue(false);
loginScene.setAlignment(Pos.CENTER);
loginScene.getChildren().addAll(recuperarLogin, recuperarSenha, login, senha, entrar, opcoes);

Scene scene = new Scene(loginScene,500,400);
// Adicionando a folha de estilos (Opcional)
Scene.getStylesheets().setAll(getClass().getResource("styles.css").toExternalForm());

stage.setScene(scene);
stage.setTitle("Sitema de Gerenciamento Acadêmico");
stage.show();

The result is as follows: inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.