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:
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
The registration form collects four essential pieces of information:
Student Name
Text field for entering the student’s first name txtNombre . setForeground ( new java. awt . Color ( 0 , 0 , 0 ));
Last Name
Text field for the student’s surname txtApellido . setForeground ( new java. awt . Color ( 0 , 0 , 0 ));
DNI (National ID)
Unique identifier used as the login username txtDni . setForeground ( new java. awt . Color ( 0 , 0 , 0 ));
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:
Name Input
Surname Input
DNI Input
Password Input
private void txtNombreActionPerformed ( java . awt . event . ActionEvent evt) {
String nombre = txtNombre . getText ();
alu . setNombre (nombre);
}
Registration Validation Logic
The system performs comprehensive validation before allowing registration. Each field is checked sequentially:
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
Step-by-Step Validation Process
Retrieve Values : Extract text from all input fields
Check Name : Verify the name field is not empty
Check Surname : Validate the apellido field has content
Check DNI : Ensure the DNI (unique identifier) is provided
Check Password : Confirm a password has been entered
Success Path : If all validations pass:
Display success message
Create Login instance with credentials
Navigate to Login screen
Hide registration form
Navigation Control
Back Navigation
Users can return to the previous screen without losing their session:
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.
Clear All Fields
The ELIMINAR (Delete) button resets all form fields to empty state:
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:
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
Initialization
The component initializes with empty form fields and creates a new Alumno instance
User Input
As users type, event handlers update the Alumno model in real-time
Validation
On registration attempt, all fields are validated sequentially
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