Overview
The logica package contains the business logic layer with two primary data model classes: Alumno (Student) and Cursos (Courses). These POJOs (Plain Old Java Objects) follow the JavaBeans pattern with private fields and public getters/setters.
Alumno Student information and credentials
Cursos Course enrollment data
Alumno Class
Represents a student’s personal information and authentication credentials.
Class Definition
package logica;
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;
}
}
Properties
nombre
apellido
dni
contraseña
Type : StringDescription : Student’s first nameGetter :public String getNombre () {
return nombre;
}
Setter :public void setNombre ( String nombre) {
this . nombre = nombre;
}
Type : StringDescription : Student’s last nameGetter :public String getApellido () {
return apellido;
}
Setter :public void setApellido ( String apellido) {
this . apellido = apellido;
}
Type : StringDescription : National identification number (Documento Nacional de Identidad)Getter :public String getDni () {
return dni;
}
Setter :public void setDni ( String dni) {
this . dni = dni;
}
The DNI serves as the username for authentication in the Login frame.
Type : StringDescription : Account passwordGetter :public String getContraseña () {
return contraseña;
}
Setter :public void setContraseña ( String contraseña) {
this . contraseña = contraseña;
}
Passwords are stored as plain text strings. In a production application, passwords should be hashed using bcrypt, PBKDF2, or similar.
Constructors
Default Constructor
Creates an empty Alumno instance: Used in the Registrar frame: Alumno alu = new Alumno ();
Parameterized Constructor
Initializes all fields: 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;
}
Usage Example
From the Registrar frame, student data is collected via text field listeners:
private void txtNombreActionPerformed ( java . awt . event . ActionEvent evt) {
String nombre = txtNombre . getText ();
alu . setNombre (nombre);
}
private void txtApellidoActionPerformed ( java . awt . event . ActionEvent evt) {
String apellido = txtApellido . getText ();
alu . setApellido (apellido);
}
private void txtDniActionPerformed ( java . awt . event . ActionEvent evt) {
String dni = txtDni . getText ();
alu . setDni (dni);
}
private void txtContraActionPerformed ( java . awt . event . ActionEvent evt) {
String contra = txtContra . getText ();
alu . setContraseña (contra);
}
Why Use ActionPerformed for Text Fields?
The action listeners trigger when the user presses Enter in each field, providing real-time data binding to the Alumno object. However, the main registration logic reads directly from the text fields to ensure all data is captured even if Enter wasn’t pressed.
Cursos Class
Represents a student’s course selections across five subject areas.
Class Definition
package logica;
public class Cursos {
String matematica , historia , ciencias , literatura , civica ;
public Cursos () {
}
public Cursos ( String matematica , String historia , String ciencias ,
String literatura , String civica ) {
this . matematica = matematica;
this . historia = historia;
this . ciencias = ciencias;
this . literatura = literatura;
this . civica = civica;
}
}
Fields are declared with package-private access (no modifier), though getters and setters are public.
Course Properties
Each property stores the full course selection string including professor, room, and schedule:
matematica
historia
ciencias
literatura
civica
Type : StringExample Value : "Matematica| Prof. Raúl Hernandez | A0504 | Lun y Mie 2:00pm a 4:00pm"public String getMatematica () {
return matematica;
}
public void setMatematica ( String matematica) {
this . matematica = matematica;
}
Type : StringExample Value : "Historia| Prof. Marisol Mercede | A0304 | Lun 10:00am a 1:00pm"public String getHistoria () {
return historia;
}
public void setHistoria ( String historia) {
this . historia = historia;
}
Type : StringExample Value : "Ciencias| Prof. Victoria Dueñas | D0405 | Mier 1:00pm a 3:00pm"public String getCiencias () {
return ciencias;
}
public void setCiencias ( String ciencias) {
this . ciencias = ciencias;
}
Type : StringExample Value : "Literat| Prof. Mario de Valle | A0107 | Mar y Sab 8:00am a 9:30am"public String getLiteratura () {
return literatura;
}
public void setLiteratura ( String literatura) {
this . literatura = literatura;
}
Type : StringExample Value : "Civica| Prof. Carmela Calderon | B0102 | Lun 8:00pm a 9:00pm"public String getCivica () {
return civica;
}
public void setCivica ( String civica) {
this . civica = civica;
}
String Representation
The class overrides toString() for debugging and logging:
@ Override
public String toString () {
return "Cursos{" +
"matematica=" + matematica +
", historia=" + historia +
", ciencias=" + ciencias +
", literatura=" + literatura +
", civica=" + civica +
'}' ;
}
Example Output :
Cursos{matematica=Matematica| Prof. Raúl Hernandez | A0504 | Lun y Mie 2:00pm a 4:00pm, historia=Historia| Prof. Marisol Mercede | A0304 | Lun 10:00am a 1:00pm, ciencias=Ninguno, literatura=Ninguno, civica=Ninguno}
Usage in Matricula Frame
Course objects are created and managed in an ArrayList:
ArrayList < Cursos > listaCursos = new ArrayList <>();
When the student clicks “Agregar cursos”:
private void btnMatematicasActionPerformed ( java . awt . event . ActionEvent evt) {
Cursos curso = new Cursos ();
curso . setMatematica ( scrMatematica . getSelectedItem (). toString ());
curso . setHistoria ( scrHistoria . getSelectedItem (). toString ());
curso . setLiteratura ( scrLiteratura . getSelectedItem (). toString ());
curso . setCivica ( scrCivica . getSelectedItem (). toString ());
curso . setCiencias ( scrCiencias . getSelectedItem (). toString ());
listaCursos . add (curso);
refrescarTabla ();
}
Each Cursos object stores a complete set of five course selections, even if some are set to “Ninguno” (None).
Data Flow Diagram
Design Patterns
JavaBeans Pattern
Both classes follow the JavaBeans specification:
Private Fields
All data is encapsulated with private (or package-private) access modifiers
No-Argument Constructor
Both classes provide a default constructor for instantiation
Getter/Setter Methods
Public methods provide controlled access to properties
Serializable (Optional)
While not implemented here, JavaBeans typically implement Serializable for persistence
Data Transfer Objects (DTOs)
These classes act as DTOs, transferring data between the presentation layer (GUI frames) and the business logic layer:
Class Source Destination Purpose AlumnoRegistrar form Login frame Authentication CursosMatricula dropdowns JTable display Course enrollment
Data Storage
Currently, the application uses in-memory storage:
No Persistence : Student and course data is lost when the application closes. All data exists only in Java objects during runtime.
Current Storage Mechanism
Created in Registrar frame
Passed to Login via constructor parameters
Not persisted beyond the session
log = new Login (dni, contra);
Stored in ArrayList<Cursos> in Matricula frame
Exists only in memory
Cleared when frame is closed
ArrayList < Cursos > listaCursos = new ArrayList <>();
Potential Enhancements
For production use, consider adding:
JDBC : Connect to MySQL, PostgreSQL, or SQLite
JPA/Hibernate : Object-relational mapping
Serialization : Save objects to files
Example table structure: CREATE TABLE alumnos (
id INT PRIMARY KEY AUTO_INCREMENT,
nombre VARCHAR ( 100 ),
apellido VARCHAR ( 100 ),
dni VARCHAR ( 20 ) UNIQUE ,
contraseña_hash VARCHAR ( 255 )
);
CREATE TABLE cursos_matriculados (
id INT PRIMARY KEY AUTO_INCREMENT,
alumno_id INT ,
matematica TEXT ,
historia TEXT ,
ciencias TEXT ,
literatura TEXT ,
civica TEXT ,
fecha_matricula TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (alumno_id) REFERENCES alumnos(id)
);
Field Validation
Neither data model class includes built-in validation. Validation is performed in the GUI layer:
Alumno Validation (in Registrar)
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 );
}
Improvement Opportunity : Move validation logic into the model classes for better separation of concerns and reusability.
Class Diagram
Best Practices
Encapsulation Private fields with public accessors protect data integrity
Constructor Overloading Multiple constructors provide flexibility in object creation
toString Override Custom string representation aids debugging
Immutability Consideration Consider making fields final and removing setters for immutable objects
Next Steps
Architecture Overview Return to the main architecture overview to see how these models fit into the complete system