Skip to main content

Overview

The Student Management component (Registrar.java) provides a comprehensive registration interface for new students. It handles data collection, validation, and secure account creation with real-time feedback.

Component Architecture

Core Structure

The Registrar class extends JFrame and manages student registration through an intuitive form interface:
Registrar.java
public class Registrar extends javax.swing.JFrame {
    private Inicio ini;
    private Login log;
    Alumno alu = new Alumno();

    public Registrar() {
        initComponents();
        this.log = new Login();
        log.setRegis(this);
    }
}
The component maintains references to both the Login screen and the student data model (Alumno), ensuring seamless navigation and data persistence.

User Interface Layout

Form Fields

The registration form collects four essential pieces of information:
1

Student Name

Text field for entering the student’s first name
txtNombre.setForeground(new java.awt.Color(0, 0, 0));
2

Last Name

Text field for the student’s surname
txtApellido.setForeground(new java.awt.Color(0, 0, 0));
3

DNI (National ID)

Unique identifier used as the login username
txtDni.setForeground(new java.awt.Color(0, 0, 0));
4

Password

Secure password field for account protection
txtContra.setForeground(new java.awt.Color(0, 0, 0));

Color Scheme

The component uses a professional teal color palette:
jPanel1.setBackground(new java.awt.Color(0, 68, 68));  // Dark teal background
jPanel1.setForeground(new java.awt.Color(0, 68, 68));

btnEliminar.setBackground(new java.awt.Color(0, 153, 153));  // Bright teal buttons
btnEliminar.setForeground(new java.awt.Color(255, 255, 255));  // White text

Event Handlers

Real-Time Data Capture

Each form field captures data as the user types, updating the Alumno model instantly:
private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {
    String nombre = txtNombre.getText();
    alu.setNombre(nombre);
}

Input Validation

Registration Validation Logic

The system performs comprehensive validation before allowing registration. Each field is checked sequentially:
Registrar.java:207-227
private void btnRegistrarseActionPerformed(java.awt.event.ActionEvent evt) {
    String nombre = txtNombre.getText();
    String apellido = txtApellido.getText();
    String dni = txtDni.getText();
    String contra = txtContra.getText();
    
    if (nombre.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU NOMBRE", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (apellido.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU APELLIDO", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (dni.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU DNI", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else if (contra.isEmpty()) {
        JOptionPane.showMessageDialog(this, "COMPLETE SU CONTRASEÑA", 
            "Advertencia", JOptionPane.WARNING_MESSAGE);
    } else {
        JOptionPane.showMessageDialog(null, "REGISTRO EXITOSO");
        log = new Login(dni, contra);
        log.setRegis(this);
        log.setVisible(true);
        log.setLocationRelativeTo(null);
        this.setVisible(false);
    }
}
The validation ensures all fields are completed before proceeding. Empty fields trigger warning dialogs with specific messages.

Validation Flow

  1. Retrieve Values: Extract text from all input fields
  2. Check Name: Verify the name field is not empty
  3. Check Surname: Validate the apellido field has content
  4. Check DNI: Ensure the DNI (unique identifier) is provided
  5. Check Password: Confirm a password has been entered
  6. Success Path: If all validations pass:
    • Display success message
    • Create Login instance with credentials
    • Navigate to Login screen
    • Hide registration form

Back Navigation

Users can return to the previous screen without losing their session:
Registrar.java:200-205
private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {
    ini.setRegistrate(this);
    ini.setVisible(true);
    ini.setLocationRelativeTo(null);
    this.setVisible(false);
}
The window is centered on screen using setLocationRelativeTo(null) for better UX.

Form Management

Clear All Fields

The ELIMINAR (Delete) button resets all form fields to empty state:
Registrar.java:230-236
private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {
    txtNombre.setText("");
    txtApellido.setText("");
    txtDni.setText("");
    txtContra.setText("");
}
This feature allows users to quickly start over without navigating away from the form.

Data Model Integration

Student Model (Alumno)

The registration component works with the Alumno data model:
Alumno.java
public class Alumno {
    private String nombre, apellido, contraseña, dni;
    
    public Alumno() {}

    public Alumno(String nombre, String apellido, String contraseña, String dni) {
        this.nombre = nombre;
        this.apellido = apellido;
        this.contraseña = contraseña;
        this.dni = dni;
    }

    // Getters and setters
    public String getNombre() { return nombre; }
    public void setNombre(String nombre) { this.nombre = nombre; }
    
    public String getApellido() { return apellido; }
    public void setApellido(String apellido) { this.apellido = apellido; }
    
    public String getDni() { return dni; }
    public void setDni(String dni) { this.dni = dni; }
    
    public String getContraseña() { return contraseña; }
    public void setContraseña(String contraseña) { this.contraseña = contraseña; }
}

Component Lifecycle

1

Initialization

The component initializes with empty form fields and creates a new Alumno instance
2

User Input

As users type, event handlers update the Alumno model in real-time
3

Validation

On registration attempt, all fields are validated sequentially
4

Success Transition

Valid data triggers navigation to Login screen with credentials passed

Key Features

Real-Time Updates

Form data is captured immediately as users interact with fields

Sequential Validation

Clear, ordered validation prevents submission of incomplete data

User Feedback

Dialog boxes provide immediate feedback on validation errors

Form Reset

Quick clear functionality for starting over

Build docs developers (and LLMs) love