Vous êtes sur la page 1sur 49

package controlador; import java.io.*; import modelo.*; public class AccesoAleatorio {

Archivos de Acceso Aleatorio

private static RandomAccessFile flujo; private static int numeroRegistros; private static int tamañoRegistro = 80;

public static void crearFileAlumno(File archivo) throws IOException {

if (archivo.exists() && !archivo.isFile()) {

throw new IOException(archivo.getName() + " no es un archivo");

} flujo = new RandomAccessFile(archivo, "rw"); numeroRegistros = (int) Math.ceil( (double) flujo.length() / (double) tamañoRegistro);

}

<a href=Archivos de Acceso Aleatorio en Java package controlador; import java.io.*; import modelo.*; public class AccesoAleatorio { Archivos de Acceso Aleatorio private static RandomAccessFile flujo; private static int numeroRegistros; private static int tamañoRegistro = 80; public static void crearFileAlumno(File archivo) throws IOException { if (archivo.exists() && !archivo.isFile()) { throw new IOException(archivo.getName() + " no es un archivo"); } flujo = new RandomAccessFile(archivo, "rw"); numeroRegistros = (int) Math.ceil( (double) flujo.length() / (double) tamañoRegistro); } public static void cerrar() throws IOException { flujo.close(); } public static boolean setPersona(int i, Persona persona) throws IOException { if(i >= 0 && i <= getNumeroRegistros()) { if(persona.getTamaño() > tamañoRegistro) { System.out.println("\nTamaño de registro excedido."); } else { flujo.seek(i*tamañoRegistro); " id="pdf-obj-0-20" src="pdf-obj-0-20.jpg">

public static void cerrar() throws IOException { flujo.close();

}

public static boolean setPersona(int i, Persona persona) throws IOException { if(i >= 0 && i <= getNumeroRegistros()) { if(persona.getTamaño() > tamañoRegistro) { System.out.println("\nTamaño de registro excedido."); } else { flujo.seek(i*tamañoRegistro);

flujo.writeUTF(persona.getNombre()); flujo.writeInt(persona.getEdad()); flujo.writeBoolean(persona.isActivo()); return true;

} } else { System.out.println("\nNúmero de registro fuera de límites.");

}

return false;

}

private static int buscarRegistroInactivo() throws IOException { String nombre; for(int i=0; i<getNumeroRegistros(); i++) {

flujo.seek(i * tamañoRegistro); if(!getPersona(i).isActivo()) return i;

}

return -1;

}

public static boolean eliminarPersona(String aEliminar) throws IOException { int pos = buscarRegistro(aEliminar); if(pos == -1) return false; Persona personaEliminada = getPersona(pos); personaEliminada.setActivo(false); setPersona(pos, personaEliminada); return true;

}

public static void compactarArchivo(File archivo) throws IOException { crearFileAlumno(archivo); // Abrimos el flujo. Persona[] listado = new Persona[numeroRegistros]; for(int i=0; i<numeroRegistros; ++i) listado[i] = getPersona(i); cerrar(); // Cerramos el flujo. archivo.delete(); // Borramos el archivo.

File tempo = new File("temporal.dat"); crearFileAlumno(tempo); // Como no existe se crea. for(Persona p : listado) if(p.isActivo()) añadirPersona(p); cerrar();

tempo.renameTo(archivo); // Renombramos.

}

public static void añadirPersona(Persona persona) throws IOException { int inactivo = buscarRegistroInactivo(); if(setPersona(inactivo==-1?numeroRegistros:inactivo, persona)) numeroRegistros++;

}

public static int getNumeroRegistros() { return numeroRegistros;

}

public static Persona getPersona(int i) throws IOException { if(i >= 0 && i <= getNumeroRegistros()) { flujo.seek(i * tamañoRegistro);

return new Persona(flujo.readUTF(), flujo.readInt(), flujo.readBoolean()); } else { System.out.println("\nNúmero de registro fuera de límites."); return null;

}

}

public static int buscarRegistro(String buscado) throws IOException { Persona p; if (buscado == null) { return -1;

} for(int i=0; i<getNumeroRegistros(); i++) { flujo.seek(i * tamañoRegistro); p = getPersona(i); if(p.getNombre().equals(buscado) && p.isActivo()) { return i;

}

}

return -1;

}

}

package modelo;

import java.io.Serializable;

public class Persona implements Serializable { private String nombre; // cada caracter ocupa 2 bytes private int edad; // ocupa 4 bytes private boolean activo;

public Persona() { nombre = "NN"; edad = 0; activo = true;

}

public Persona(String nombre, int edad, boolean activo) { this.nombre = nombre; this.edad = edad; this.activo = activo;

}

public void setNombre(String nombre) { this.nombre = nombre;

}

public String getNombre() { return nombre;

}

public void setEdad(int edad) { this.edad = edad;

}

public int getEdad() { return edad;

}

public boolean isActivo() { return activo;

}

public void setActivo(boolean activo) { this.activo = activo;

}

@Override public String toString() { return "\nNombre: " + nombre + "\nEdad: " + edad;

}

public int getTamaño() { return getNombre().length()*2 + 2 + 4 + 1;

}

}

package vista;

import controlador.AccesoAleatorio; import java.io.File; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import modelo.Persona;

/** * @author JCarlos Ramos Suyón; */ public class Principal extends javax.swing.JFrame {

public Principal() { initComponents();

}

@SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {

jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); txtNombre = new javax.swing.JTextField(); txtEdad = new javax.swing.JTextField(); btnAdd = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); txtBusqueda = new javax.swing.JTextField(); btnSearch = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); campoEliminar = new javax.swing.JTextField(); btnEliminar = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Archivos :: Acceso Aleatorio"); setMinimumSize(new java.awt.Dimension(244, 355)); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt);

}

});

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Registrar nueva persona"));

jLabel1.setText("Ingrese nombre:");

jLabel2.setText("Ingrese edad:");

txtNombre.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtNombreFocusGained(evt);

}

});

txtEdad.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtEdadFocusGained(evt);

}

});

btnAdd.setText("Agregar persona"); btnAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddActionPerformed(evt);

}

});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

.addComponent(jLabel1)

.addComponent(jLabel2))

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(txtEdad) .addComponent(txtNombre)) .addGap(10, 10, 10))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(btnAdd, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) .addContainerGap())))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel1)

.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2)

.addComponent(txtEdad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(btnAdd) .addContainerGap(12, Short.MAX_VALUE))

);

jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar persona registrada"));

jLabel3.setText("Nombre a buscar:");

txtBusqueda.addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { txtBusquedaFocusGained(evt);

}

});

btnSearch.setText("Buscar persona"); btnSearch.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSearchActionPerformed(evt);

}

});

javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);

jPanel2.setLayout(jPanel2Layout);

jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel2Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(btnSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(jPanel2Layout.createSequentialGroup()

.addComponent(jLabel3)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(txtBusqueda)))

.addContainerGap())

);

jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel2Layout.createSequentialGroup()

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel3)

.addComponent(txtBusqueda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(btnSearch))

);

jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Eliminar persona registrada"));

jLabel4.setText("Nombre de la persona a eliminar:");

btnEliminar.setText("Eliminar persona"); btnEliminar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEliminarActionPerformed(evt);

}

});

javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);

jPanel3.setLayout(jPanel3Layout);

jPanel3Layout.setHorizontalGroup(

jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel3Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(campoEliminar)

.addGroup(jPanel3Layout.createSequentialGroup()

.addComponent(jLabel4)

.addGap(0, 0, Short.MAX_VALUE)) .addComponent(btnEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap())

);

jPanel3Layout.setVerticalGroup(

jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel3Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel4)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(campoEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnEliminar) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

pack(); setLocationRelativeTo(null); }// </editor-fold>

private void btnAddActionPerformed(java.awt.event.ActionEvent evt) { String nombre = txtNombre.getText().trim(); if(nombre.isEmpty()) {

JOptionPane.showMessageDialog(this, "¡No se ingreso el nombre de la persona!", "Advertencia", JOptionPane.WARNING_MESSAGE);

return;

}

String _edad = txtEdad.getText().trim(); if(_edad.isEmpty()) {

JOptionPane.showMessageDialog(this, "¡No se ingreso la edad de la persona!", "Advertencia", JOptionPane.WARNING_MESSAGE);

return;

} int edad; try { edad = Integer.parseInt(_edad); } catch(NumberFormatException nfe) {

JOptionPane.showMessageDialog(this, "Debe ingresar un número entero para la edad.", "Error", JOptionPane.ERROR_MESSAGE);

return;

} try { AccesoAleatorio.crearFileAlumno( new File("personas.dat") ); AccesoAleatorio.añadirPersona( new Persona(nombre, edad, true) ); AccesoAleatorio.cerrar();

JOptionPane.showMessageDialog(this, "El registro se realizó correctamente.", "Notificación", JOptionPane.INFORMATION_MESSAGE);

} catch (IOException ex) {

JOptionPane.showMessageDialog(this, "Error en la escritura de datos.", "Error", JOptionPane.ERROR_MESSAGE);

}

}

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) { String nombre = txtBusqueda.getText().trim(); if(nombre.isEmpty()) {

JOptionPane.showMessageDialog(this, "¡No se ingreso el nombre de la persona!", "Advertencia", JOptionPane.WARNING_MESSAGE);

return;

}

try { AccesoAleatorio.crearFileAlumno( new File("personas.dat") ); int i = AccesoAleatorio.buscarRegistro( nombre ); if(i==-1) {

JOptionPane.showMessageDialog(this, "Ningún registro coincide con los datos de búsqueda.", "Advertencia", JOptionPane.WARNING_MESSAGE);

return;

}

JOptionPane.showMessageDialog(this, "La primera coincidencia indica:

"+AccesoAleatorio.getPersona(i), "Notificación", JOptionPane.INFORMATION_MESSAGE);

AccesoAleatorio.cerrar(); } catch(IOException e) {

JOptionPane.showMessageDialog(this, "Error en la búsqueda de registros.", "Error", JOptionPane.ERROR_MESSAGE);

}

}

private void txtNombreFocusGained(java.awt.event.FocusEvent evt) { txtNombre.selectAll();

}

private void txtEdadFocusGained(java.awt.event.FocusEvent evt) { txtEdad.selectAll();

}

private void txtBusquedaFocusGained(java.awt.event.FocusEvent evt) { txtBusqueda.selectAll();

}

private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) { try { AccesoAleatorio.crearFileAlumno(new File("personas.dat"));

if( AccesoAleatorio.eliminarPersona(campoEliminar.getText()) )

JOptionPane.showMessageDialog(this, "El registro correspondiente fue eliminado correctamente.", "Eliminación correcta", JOptionPane.INFORMATION_MESSAGE);

else JOptionPane.showMessageDialog(this, "Error al intentar eliminar un registro inexistente.", "Error", JOptionPane.ERROR_MESSAGE);

} catch (IOException ex) {

JOptionPane.showMessageDialog(this, "Error en la eliminación de registros.", "Error", JOptionPane.ERROR_MESSAGE);

}

}

private void formWindowClosing(java.awt.event.WindowEvent evt) { try { AccesoAleatorio.compactarArchivo(new File("personas.dat")); } catch (IOException ex) {

JOptionPane.showMessageDialog(this, "Error al tratar de compactar el archivo:

"+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

}

}

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new Principal().setVisible(true);

}

});

}

// Variables declaration - do not modify private javax.swing.JButton btnAdd; private javax.swing.JButton btnEliminar;

private javax.swing.JButton btnSearch; private javax.swing.JTextField campoEliminar; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JTextField txtBusqueda; private javax.swing.JTextField txtEdad; private javax.swing.JTextField txtNombre; // End of variables declaration

}

package Inicio;

import java.io.Serializable;

public class Empleados implements Serializable {

private String codigo; private String nombre; private int horas; private double pago; private double pago_hora; private String puesto; private String planilla; private String modalidad;

private javax.swing.JButton btnSearch; private javax.swing.JTextField campoEliminar; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private

private double bonificacion; private double descuento; private double monto;

public Empleados() {

}

public Empleados(String cod,String nomb,int h,double pag,double ph,String pu,String mod,String pla,double bo,double des,double mon)

{

 

this.setCodigo(cod);

this.setNombre(nomb);

this.setHoras(h);

this.setPago(pag);

this.setPago_hora(ph);

this.setPuesto(pu);

this.setModalidad(mod);

this.setPlanilla(pla);

this.setBonificacion(bo);

this.setDescuento(des);

this.setMonto(mon);

}

public String getCodigo() { return codigo;

}

public void setCodigo(String codigo) { this.codigo = codigo;

}

public String getNombre() { return nombre;

}

public void setNombre(String nombre) { this.nombre = nombre;

}

public int getHoras() { return horas;

}

public void setHoras(int horas) { this.horas = horas;

}

public double getPago() { return pago;

}

public void setPago(double pago) { this.pago = pago;

}

public double getPago_hora() { return pago_hora;

}

public void setPago_hora(double pago_hora) {

this.pago_hora = pago_hora;

}

public String getPuesto() { return puesto;

}

public void setPuesto(String puesto) { this.puesto = puesto;

}

public String getPlanilla() { return planilla;

}

public void setPlanilla(String planilla) { this.planilla = planilla;

}

public String getModalidad() { return modalidad;

}

public void setModalidad(String modalidad) { this.modalidad = modalidad;

}

public double getBonificacion() { return bonificacion;

}

public void setBonificacion(double bonificacion) { this.bonificacion = bonificacion;

}

public double getDescuento() { return descuento;

}

public void setDescuento(double descuento) { this.descuento = descuento;

}

public double getMonto() { return monto;

}

public void setMonto(double monto) { this.monto = monto;

}

public double pago_hora(String puesto, int horas) {

double pa = 0; if(puesto.equalsIgnoreCase("Capataz")){ pa = 55.00 * horas; }else if(puesto.equalsIgnoreCase("Maestro")){ pa = 42.00 * horas; }else if(puesto.equalsIgnoreCase("Operario")){ pa = 25.00 * horas;

}

return pa;

}

public double bonificacion(double pago, String modalidad) {

double bo=0; if(modalidad.equalsIgnoreCase("Estable")){ bo = 0.25 * pago; }else if(modalidad.equalsIgnoreCase("Contratado")){ bo = 0.10 * pago;

}

return bo;

}

public double p_incial(double pago, double bonificacion) {

return pago + bonificacion;

}

public double Descuento(String planilla, double pa){ double des=0; if(planilla.equalsIgnoreCase("AFP")){ des = 0.035 * pa; }else if(planilla.equalsIgnoreCase("SEGURO")){ des = 0.03 * pa; }else if(planilla.equalsIgnoreCase("FONAVI")){ des = 0.025 * pa;

}

return des;

}

public double Monto(double pago, double descuento){

return pago - descuento;

}

}

package Inicio;

import java.util.ArrayList; import java.io.Serializable;

public class aEmpleados implements Serializable {

// Creamos el ArrayList de la Clase Empleado private ArrayList <Empleados> e;

// Inicializamos el ArrayList dentro del constructor aEmpleado public aEmpleados() {

e = new ArrayList();

}

// Metodod Insertar al arrayList public void Agregar(Empleados em) {

e.add(em);

}

// Metodod devolver la posicion del objeto dentro del arrayList public Empleados getEmpleado(int i) {

return e.get(i);

}

// Metodod Modificar al arrayList public void Actualizar(int p, Empleados nuevo) {

e.set(p, nuevo);

}

// Metodod Eliminar al arrayList public void Eliminar(int p) {

e.remove(p);

}

// Metodod EliminarTodo al arrayList public void ElimiarTodos() {

int n = this.getNumero(); for(int p=0; p<n; p++) {

 

e.remove(0);

}

}

// Metodod devolver el tamaño del arrayList public int getNumero() {

return e.size();

}

// Metodod para Buscar la posicion donde se encuentre el objeto // dentro del arrayList

public int buscar(String codigo) {

int n = this.getNumero(); for(int p=0; p<n; p++) {

if(codigo.equalsIgnoreCase(this.getEmpleado(p).getCodigo()))

{

 

return p;

}

}

return -1;

}

}

package Inicio;

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.text.DecimalFormat; import javax.swing.JOptionPane; import javax.swing.table.*;

public class Interfaz extends javax.swing.JFrame {

DefaultTableModel miModelo; Empleados open; aEmpleados a; String[] cabecera={"CODIGO","NOMBRE","HORAS","PAGO","PAGO.HORA","PUESTO","MODALIDAD","P LANILLA","BONIFICACION","DESCUENTO","SUELDO"};

String[][] data={};

int cont=0;

public Interfaz() { initComponents(); miModelo = new DefaultTableModel(data,cabecera); jtable.setModel(miModelo); a = new aEmpleados(); cargaDatos(); actualizar();

}

public void escribir(String texto) {

JOptionPane.showMessageDialog(this, texto);

}

public void cargaDatos() {

try{ FileInputStream fis = new FileInputStream("Empleados.bin"); ObjectInputStream in = new ObjectInputStream(fis); if(in != null) {

a = (aEmpleados) in.readObject(); in.close();

} }catch(Exception ex){ escribir(ex.getMessage());

}

}

public void grabar() {

try{ FileOutputStream fos = new FileOutputStream("Empleados.bin"); ObjectOutputStream out = new ObjectOutputStream(fos); if(out != null){ out.writeObject(a); out.close();

} }catch(Exception ex){ escribir(ex.getMessage());

}

}

public void vaciar_tabla(){ int n = jtable.getRowCount(); for(int p=0;p<n;p++){

miModelo.removeRow(0);

}

}

public void actualizar(){ vaciar_tabla(); int n = a.getNumero(); for(int p=0; p<n; p++){ open = a.getEmpleado(p); String cod = open.getCodigo(); String nomb = open.getNombre(); int ht = open.getHoras(); double pa = open.getPago();

double ph = open.getPago_hora();

String pu = open.getPuesto();

String mo = open.getModalidad();

String pla = open.getPlanilla();

double bo = open.getBonificacion();

double des = open.getDescuento();

double mont = open.getMonto();

insertar(cod,nomb,ht,pa,ph,pu,mo,pla,bo,des,mont);

}

}

public void insertar(String cod,String nomb,int ht,double pa,double ph,String pu,String

mo,String pla,double bo,double des,double mont){

DecimalFormat d = new DecimalFormat("####.00");

String pago = d.format(ph);

String boni = d.format(bo);

String desc = d.format(des);

String monto = d.format(mont);

Object[] fila={cod, nomb, ht, pa, pago, pu, mo, pla, boni, desc, monto};

miModelo.addRow(fila);

}

public void m_borrar(){

String op = JOptionPane.showInputDialog("Codigo a borrar : ");

int p = a.buscar(op);

if(p == -1){

escribir("Codigo no existe");

}else{

int i = JOptionPane.showConfirmDialog(null,"Estas seguro de borrar

...

");

if(i==0){

a.Eliminar(p);

grabar();

actualizar();

}else if(i==1){

escribir("Vuela a intentarlo");

}

}

}

public void m_consultar(){

String co = JOptionPane.showInputDialog("Buscar por el codigo

....

");

int p = a.buscar(co);

int n = a.getNumero();

if(p == -1){

escribir("Codigo no existe");

}else{

for(int i=0; i<n; i++){

open = a.getEmpleado(p);

String cod = open.getCodigo();

String nomb = open.getNombre();

int ht = open.getHoras();

double pa = open.getPago();

double ph = open.getPago_hora();

String pu = open.getPuesto();

String mo = open.getModalidad();

String pla = open.getPlanilla();

double bo = open.getBonificacion();

double des = open.getDescuento();

double mont = open.getMonto();

JTFCodigo.setText(cod);

JTFNombre.setText(nomb);

JTFHoras.setText(String.valueOf(ht));

JTFPago.setText(String.valueOf(pa));

if(pu.equalsIgnoreCase("Capataz")){

JCBPuesto.setSelectedIndex(1);

}else if(pu.equalsIgnoreCase("Maestro")){

JCBPuesto.setSelectedIndex(2);

}else if(pu.equalsIgnoreCase("Operario")){

JCBPuesto.setSelectedIndex(3);

}

if(mo.equalsIgnoreCase("Estable")){

JCBModalidad.setSelectedIndex(1);

}else if(mo.equalsIgnoreCase("Contratado")){

JCBModalidad.setSelectedIndex(2);

}

if(pla.equalsIgnoreCase("AFP")){

JCBPlanilla.setSelectedIndex(1);

}else if(pla.equalsIgnoreCase("SEGURO")){

JCBPlanilla.setSelectedIndex(2);

}else if(pla.equalsIgnoreCase("FONAVI")){

JCBPlanilla.setSelectedIndex(3);

}

}

}

}

public void m_modificar(){

int op = JOptionPane.showConfirmDialog(null,"Deves consultar primero \nDeseas

consultar ahora presiona <Si>\nSi ya consultastes presionsa <No>");

if(op==0){

m_consultar();

}else if(op==1){

int n = a.getNumero();

for(int p=0;p<n;p++){

String co = JTFCodigo.getText();

String nomb = JTFNombre.getText();

int ht = Integer.parseInt(JTFHoras.getText());

String pu = JCBPuesto.getSelectedItem().toString();

double pa = Double.parseDouble(JTFPago.getText());

double ph = open.pago_hora(pu,ht);

String mo = JCBModalidad.getSelectedItem().toString();

double bo = open.bonificacion(ph,mo);

double pi = open.p_incial(ph,bo);

String pla = JCBPlanilla.getSelectedItem().toString();

double des = open.Descuento(pla,pa);

double monto = open.Monto(ph,des);

open = new Empleados(co,nomb,ht,pa,ph,pu,mo,pla,bo,des,monto);

int i = a.buscar(co);

if(i == -1){

a.Agregar(open);

}else{

a.Actualizar(i, open);

grabar();

actualizar();

limpiar();

}

}

}

}

public void limpiar(){

JTFCodigo.setText("");

JTFHoras.setText("");

JTFNombre.setText("");

JTFPago.setText("");

JCBPuesto.setSelectedIndex(0);

JCBPlanilla.setSelectedIndex(0);

JCBModalidad.setSelectedIndex(0);

JTFCodigo.requestFocus();

}

public void m_guardar(){

int ne = Integer.parseInt(JTFEmpleados.getText());

if(cont < ne){

cont++;

Empleados em = new Empleados();

String co = JTFCodigo.getText();

String nomb = JTFNombre.getText();

int ht = Integer.parseInt(JTFHoras.getText());

String pu = JCBPuesto.getSelectedItem().toString();

double pa = Double.parseDouble(JTFPago.getText());

double ph = em.pago_hora(pu,ht);

String mo = JCBModalidad.getSelectedItem().toString();

double bo = em.bonificacion(ph,mo);

double pi = em.p_incial(ph,bo);

String pla = JCBPlanilla.getSelectedItem().toString();

double des = em.Descuento(pla,pa);

double monto = em.Monto(ph ,des);

open = new Empleados(co,nomb,ht,pa,ph,pu,mo,pla,bo,des,monto);

if(a.buscar(open.getCodigo()) != -1){

escribir("El codigo del empleado ya existe");

}else{

a.Agregar(open);

insertar(co,nomb,ht,pa,ph,pu,mo,pla,bo,des,monto);

grabar();

actualizar();

limpiar();

}

}else{

escribir("N° empleados ya registrados");

}

}

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jbConsultar = new javax.swing.JButton();

jbModificar = new javax.swing.JButton();

jbBorrar = new javax.swing.JButton();

jLabel9 = new javax.swing.JLabel();

JCBPuesto = new javax.swing.JComboBox();

jLabel12 = new javax.swing.JLabel();

JCBModalidad = new javax.swing.JComboBox();

JTFNombre = new javax.swing.JTextField();

jLabel13 = new javax.swing.JLabel();

JTFHoras = new javax.swing.JTextField();

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

JTFEmpleados = new javax.swing.JTextField();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

jLabel5 = new javax.swing.JLabel();

JCBPlanilla = new javax.swing.JComboBox();

JTFPago = new javax.swing.JTextField();

jLabel14 = new javax.swing.JLabel();

jbGuardar = new javax.swing.JButton();

JTFCodigo = new javax.swing.JTextField();

jScrollPane1 = new javax.swing.JScrollPane();

jtable = new javax.swing.JTable();

jPanel1 = new javax.swing.JPanel();

jLabel7 = new javax.swing.JLabel();

jLabel8 = new javax.swing.JLabel();

JCBBuscar = new javax.swing.JComboBox();

jLabel10 = new javax.swing.JLabel();

jLabel11 = new javax.swing.JLabel();

jScrollPane2 = new javax.swing.JScrollPane();

JTABoleta = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jbConsultar.setText("Consultar");

jbConsultar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jbConsultarActionPerformed(evt);

}

});

jbModificar.setText("Modificar");

jbModificar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jbModificarActionPerformed(evt);

}

});

jbBorrar.setText("Borrar");

jbBorrar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jbBorrarActionPerformed(evt);

}

});

jLabel9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel9.setText("Puesto del empleado");

JCBPuesto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----------",

"Capataz", "Maestro", "Operario" }));

JCBPuesto.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

JCBPuestoActionPerformed(evt);

}

});

jLabel12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel12.setText("Modalidad");

JCBModalidad.setModel(new javax.swing.DefaultComboBoxModel(new String[]

{ "-------------", "Estable", "Contratado" }));

jLabel13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel13.setText("Descuento por planilla");

jLabel1.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N

jLabel1.setText("EMPRESA BOXER S.A. ");

jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel2.setText("N° empleados");

jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel3.setText("Nombre del empleado:");

jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel4.setText("Horas trabajadas");

jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel5.setText("Pago por hora");

JCBPlanilla.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----------",

"AFP", "SEGURO", "FONAVI" }));

jLabel14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel14.setText("Codigo del empleado");

jbGuardar.setText("Guardar");

jbGuardar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jbGuardarActionPerformed(evt);

}

});

jtable.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

},

new String [] {

}

));

jScrollPane1.setViewportView(jtable);

jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0,

0)));

jLabel7.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N

jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

jLabel7.setText("Resumen");

jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel8.setText("buscar por :");

JCBBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----------",

"Capataz", "Maestro", "Operario" }));

JCBBuscar.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

JCBBuscarActionPerformed(evt);

}

});

jLabel10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel10.setText("Determinar el monto total que la empresa gastara");

jLabel11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel11.setText("en pagar a sus empleados y cuanto pagara según el Puesto.");

JTABoleta.setColumns(20);

JTABoleta.setRows(5);

jScrollPane2.setViewportView(JTABoleta);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);

jPanel1.setLayout(jPanel1Layout);

jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel8)

.addGap(18, 18, 18)

.addComponent(JCBBuscar, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(31, 31, 31))

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel10)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))

.addGroup(jPanel1Layout.createSequentialGroup()

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 377,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(jPanel1Layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel11)))

.addGap(0, 56, Short.MAX_VALUE))

);

jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createSequentialGroup()

.addComponent(jLabel7)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel10)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jLabel11)

.addGap(18, 18, 18)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel8)

.addComponent(JCBBuscar, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 105,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING,

javax.swing.GroupLayout.DEFAULT_SIZE, 810, Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)

.addGroup(javax.swing.GroupLayout.Alignment.LEADING,

layout.createSequentialGroup()

.addComponent(jLabel2)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(JTFEmpleados,

javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(javax.swing.GroupLayout.Alignment.LEADING,

layout.createSequentialGroup()

.addComponent(jLabel14)

.addGap(60, 60, 60)

.addComponent(JTFCodigo, javax.swing.GroupLayout.PREFERRED_SIZE,

100, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel3)

.addGap(49, 49, 49)

.addComponent(JTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 150,

javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGap(107, 107, 107)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jbGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 122,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jbModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 128,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(27, 27, 27)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(jbBorrar, javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jbConsultar, javax.swing.GroupLayout.DEFAULT_SIZE, 137,

Short.MAX_VALUE))

.addGap(0, 0, Short.MAX_VALUE))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel4)

.addGap(84, 84, 84)

.addComponent(JTFHoras, javax.swing.GroupLayout.PREFERRED_SIZE, 59,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel9)

.addComponent(jLabel5))

.addGap(61, 61, 61)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(JTFPago, javax.swing.GroupLayout.PREFERRED_SIZE, 100,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(JCBPuesto, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel12)

.addComponent(jLabel13))

.addGap(54, 54, 54)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(JCBPlanilla, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(JCBModalidad,

javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.PREFERRED_SIZE))))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap())

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,

layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jbGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 41,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jbConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 36,

javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(35, 35, 35)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jbModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 31,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jbBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, 35,

javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGroup(layout.createSequentialGroup()

.addGap(73, 73, 73)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2)

.addComponent(JTFEmpleados, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(JTFCodigo, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel14))

.addGap(13, 13, 13)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(JTFNombre, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel3))))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,

false)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel4)

.addComponent(JTFHoras, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(JCBPuesto, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel9))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(JTFPago, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel5))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel12)

.addComponent(JCBModalidad, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel13)

.addComponent(JCBPlanilla, javax.swing.GroupLayout.PREFERRED_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,

javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

.addGap(18, 18, 18)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158,

javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jLabel1)

.addContainerGap(533, Short.MAX_VALUE)))

);

pack();

}// </editor-fold>

private void JCBPuestoActionPerformed(java.awt.event.ActionEvent evt) {

int pu = JCBPuesto.getSelectedIndex();

switch(pu){

case 1 : JTFPago.setText("55.00");break;

case 2 : JTFPago.setText("42.00");break;

case 3 : JTFPago.setText("25.00");break;

}

}

private void jbBorrarActionPerformed(java.awt.event.ActionEvent evt) {

this.m_borrar();

}

private void jbModificarActionPerformed(java.awt.event.ActionEvent evt) {

this.m_modificar();

}

private void jbConsultarActionPerformed(java.awt.event.ActionEvent evt) {

this.m_consultar();

}

private void jbGuardarActionPerformed(java.awt.event.ActionEvent evt) {

this.m_guardar();

}

private void JCBBuscarActionPerformed(java.awt.event.ActionEvent evt) {

this.m_resumen();

}

public void m_resumen(){

double sum=0,s1=0,s2=0,s3=0;

int n = a.getNumero();

for(int p=0;p<n;p++){

open = a.getEmpleado(p);

String cod = open.getCodigo();

String nomb = open.getNombre();

int ht = open.getHoras();

double pa = open.getPago();

double ph = open.getPago_hora();

String pu = open.getPuesto();

String mo = open.getModalidad();

String pla = open.getPlanilla();

double bo = open.getBonificacion();

double des = open.getDescuento();

double mont = open.getMonto();

sum = sum + mont;

if(pu.equalsIgnoreCase("Capataz")){

s1=s1+mont;

}else if(pu.equalsIgnoreCase("Maestro")){

s2=s2+mont;

}else if(pu.equalsIgnoreCase("Operario")){

 

s3=s3+mont;

 

}

}

DecimalFormat d = new DecimalFormat("####.00");

String s = d.format(sum);

String ss1 = d.format(s1);

String ss2 = d.format(s2);

String ss3 = d.format(s3);

int op = JCBBuscar.getSelectedIndex();

switch(op){

case 1 : JTABoleta.setText("");

JTABoleta.append("\n\nMonto total es: "+s);

JTABoleta.append("\nMonto a pagar por Capataz : "+ss1);

break;

case 2 : JTABoleta.setText("");

JTABoleta.append("\n\nMonto total es: "+s);

JTABoleta.append("\nMonto a pagar por Capataz : "+ss2);

break;

case 3 : JTABoleta.setText("");

JTABoleta.append("\n\nMonto total es: "+s);

JTABoleta.append("\nMonto a pagar por Capataz : "+ss3);

break;

}

}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see

http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info :

javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

}

}

} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE,

null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE,

null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE,

null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Interfaz.class.getName()).log(java.util.logging.Level.SEVERE,

null, ex);

}

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Interfaz().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JComboBox JCBBuscar;

private javax.swing.JComboBox JCBModalidad;

private javax.swing.JComboBox JCBPlanilla;

private javax.swing.JComboBox JCBPuesto;

private javax.swing.JTextArea JTABoleta;

private javax.swing.JTextField JTFCodigo;

private javax.swing.JTextField JTFEmpleados;

private javax.swing.JTextField JTFHoras;

private javax.swing.JTextField JTFNombre;

private javax.swing.JTextField JTFPago;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel10;

private javax.swing.JLabel jLabel11;

private javax.swing.JLabel jLabel12;

private javax.swing.JLabel jLabel13;

private javax.swing.JLabel jLabel14;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel7;

private javax.swing.JLabel jLabel8;

private javax.swing.JLabel jLabel9;

private javax.swing.JPanel jPanel1;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JScrollPane jScrollPane2;

private javax.swing.JButton jbBorrar;

private javax.swing.JButton jbConsultar;

private javax.swing.JButton jbGuardar;

private javax.swing.JButton jbModificar;

private javax.swing.JTable jtable;

// End of variables declaration

}