Código Java Applet para Gestión de Préstamos Bancarios: Ejemplo de Interfaz con Swing

Informática y Telecomunicaciones8,11 KB

Código Java: Applet para la Gestión de Préstamos Bancarios

A continuación se presenta el código fuente de un JApplet en Java que permite gestionar deudores de un banco: ingresar clientes, mostrar la lista de deudores y eliminar clientes mediante su cédula.

Descripción general

  • Ingreso de datos del cliente: nombre, cédula, fechas de inicio y finalización, monto del préstamo, tasa de interés y número de cuotas.
  • Selección de operaciones mediante JRadioButton: ingresar, mostrar o borrar clientes.
  • Uso de ActionListener e ItemListener para gestionar eventos.

Código fuente

/**
* @(#)PruebaBanco.java
*
* PruebaBanco Applet application
*
* @author
* @version 1.00 2011/3/13
*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class PruebaBanco extends JApplet implements ActionListener, ItemListener {

JLabel lInformacion, lNombre, lCI, lFechaInicio, lFechaFinal, lPrestamo, lTaza, lCuotas;
JTextField tNombre, tCI, tFechaInicioDia, tFechaInicioMes, tFechaInicioAño, tFechafinalDia, tFechafinalMes, tFechafinalAño, tPrestamo, tTaza, tCuotas;
JRadioButton rbIngresarCliente, rbBorrarCliente, rbMostrarCliente;
ButtonGroup b;
JButton bAceptar;

Fecha fechaInicio;
Fecha fechaFinal;
String monto, nombre, ci;
float taza, cuotas;
int diaInicio, mesInicio, añoInicio, diaFin, mesFin, añoFin;
Prestamo prestamo;
Cliente cliente;
Deudores listaDeudores = new Deudores(100);

public void init() {
setLayout(new FlowLayout());

lInformacion = new JLabel("Introduzca los siguientes datos para realizar la creación del nuevo deudor");
lNombre = new JLabel("Nombre y Apellido");
lCI = new JLabel("Cédula");
lFechaInicio = new JLabel("Fecha de inicio (dd/mm/aa)");
lFechaFinal = new JLabel("Fecha de culminación (dd/mm/aa)");
lPrestamo = new JLabel("Préstamo Bs.F");
lTaza = new JLabel("Tasa de interés");
lCuotas = new JLabel("Cuotas");

tNombre = new JTextField(15);
tCI = new JTextField(9);
tFechaInicioDia = new JTextField(2);
tFechaInicioMes = new JTextField(2);
tFechaInicioAño = new JTextField(2);
tFechafinalDia = new JTextField(2);
tFechafinalMes = new JTextField(2);
tFechafinalAño = new JTextField(2);
tPrestamo = new JTextField(5);
tTaza = new JTextField(3);
tCuotas = new JTextField(3);

rbIngresarCliente = new JRadioButton("Ingresar Cliente", true);
rbMostrarCliente = new JRadioButton("Mostrar Clientes");
rbBorrarCliente = new JRadioButton("Borrar Clientes");

bAceptar = new JButton("AGREGAR");

rbMostrarCliente.addItemListener(this);
rbBorrarCliente.addItemListener(this);
rbIngresarCliente.addItemListener(this);

b = new ButtonGroup();
b.add(rbIngresarCliente);
b.add(rbBorrarCliente);
b.add(rbMostrarCliente);

bAceptar.addActionListener(this);

add(rbIngresarCliente);
add(rbMostrarCliente);
add(rbBorrarCliente);

add(lInformacion);
add(lNombre);
add(tNombre);
add(lCI);
add(tCI);
add(lFechaInicio);
add(tFechaInicioDia);
add(tFechaInicioMes);
add(tFechaInicioAño);
add(lFechaFinal);
add(tFechafinalDia);
add(tFechafinalMes);
add(tFechafinalAño);
add(lPrestamo);
add(tPrestamo);
add(lTaza);
add(tTaza);
add(lCuotas);
add(tCuotas);

add(bAceptar);

}

public void paint(Graphics g) {
super.paint(g);
}

public void itemStateChanged(ItemEvent i) {

if (i.getSource().equals(rbIngresarCliente)) {
lInformacion.setText("Presione el botón para cargar la lista de deudores");
lNombre.setText("NOMBRE Y APELLIDO");
lCI.setText("CÉDULA");
lFechaInicio.setText("FECHA DE INICIO (dd/mm/aa)");
lFechaFinal.setText("FECHA DE FINALIZACIÓN (dd/mm/aa)");
lPrestamo.setText("PRÉSTAMO");
lTaza.setText("TASA DE INTERÉS");
lCuotas.setText("CUOTAS");
bAceptar.setText("AGREGAR");
tNombre.setVisible(true);
tCI.setVisible(true);
tFechaInicioDia.setVisible(true);
tFechaInicioMes.setVisible(true);
tFechaInicioAño.setVisible(true);
tFechafinalDia.setVisible(true);
tFechafinalMes.setVisible(true);
tFechafinalAño.setVisible(true);
tPrestamo.setVisible(true);
tTaza.setVisible(true);
tCuotas.setVisible(true);

} else if (i.getSource().equals(rbMostrarCliente)) {
lInformacion.setText("Presione el botón para cargar la lista de deudores");
lNombre.setText("");
lCI.setText("");
lFechaInicio.setText("");
lFechaFinal.setText("");
lPrestamo.setText("");
lTaza.setText("");
lCuotas.setText("");
bAceptar.setText("MOSTRAR");
tNombre.setVisible(false);
tCI.setVisible(false);
tFechaInicioDia.setVisible(false);
tFechaInicioMes.setVisible(false);
tFechaInicioAño.setVisible(false);
tFechafinalDia.setVisible(false);
tFechafinalMes.setVisible(false);
tFechafinalAño.setVisible(false);
tPrestamo.setVisible(false);
tTaza.setVisible(false);
tCuotas.setVisible(false);

} else {
lInformacion.setText("Introduzca el número de cédula del cliente a eliminar");
lNombre.setText("");
lCI.setText("CÉDULA");
lFechaInicio.setText("");
lFechaFinal.setText("");
lPrestamo.setText("");
lTaza.setText("");
lCuotas.setText("");
bAceptar.setText("ELIMINAR");
tNombre.setVisible(false);
tCI.setVisible(true);
tFechaInicioDia.setVisible(false);
tFechaInicioMes.setVisible(false);
tFechaInicioAño.setVisible(false);
tFechafinalDia.setVisible(false);
tFechafinalMes.setVisible(false);
tFechafinalAño.setVisible(false);
tPrestamo.setVisible(false);
tTaza.setVisible(false);
tCuotas.setVisible(false);
}

}

public void actionPerformed(ActionEvent a) {
if (rbIngresarCliente.isSelected()) {
String nombre = tNombre.getText();
String ci = tCI.getText();
int diaInicio = Integer.parseInt(tFechaInicioDia.getText());
int mesInicio = Integer.parseInt(tFechaInicioMes.getText());
int añoInicio = Integer.parseInt(tFechaInicioAño.getText());
int diaFin = Integer.parseInt(tFechafinalDia.getText());
int mesFin = Integer.parseInt(tFechafinalMes.getText());
int añoFin = Integer.parseInt(tFechafinalAño.getText());
String monto = tPrestamo.getText();
float taza = Float.parseFloat(tTaza.getText());
float cuotas = Float.parseFloat(tCuotas.getText());
fechaInicio = new Fecha(diaInicio, mesInicio, añoInicio);
fechaFinal = new Fecha(diaFin, mesFin, añoFin);
prestamo = new Prestamo(fechaInicio, fechaFinal, monto, cuotas, taza);
cliente = new Cliente(nombre, ci, prestamo);
JOptionPane.showMessageDialog(null, listaDeudores.ingresarDeudor(cliente));

} else if (rbMostrarCliente.isSelected()) {
JOptionPane.showMessageDialog(null, listaDeudores.mostrarDeudores());
} else if (rbBorrarCliente.isSelected()) {
JOptionPane.showMessageDialog(null, listaDeudores.eliminarDeudor(tCI.getText()));
} else {
JOptionPane.showMessageDialog(null, "Debes seleccionar alguna de las opciones");
}

tNombre.setText("");
tCI.setText("");
tFechaInicioDia.setText("");
tFechaInicioMes.setText("");
tFechaInicioAño.setText("");
tFechafinalDia.setText("");
tFechafinalMes.setText("");
tFechafinalAño.setText("");
tPrestamo.setText("");
tTaza.setText("");
tCuotas.setText("");
}

}

Descargar

PDF Word HTML