0% found this document useful (0 votes)
34 views6 pages

FINALLP

The document describes a Java program that uses a doubly linked list to store and manage employee data. It defines classes for the linked list nodes (NodoDoble) and the linked list itself (PrgListaDoble). The main window class (winListaDoble) allows users to add, view, search, and update employee records stored in the linked list.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views6 pages

FINALLP

The document describes a Java program that uses a doubly linked list to store and manage employee data. It defines classes for the linked list nodes (NodoDoble) and the linked list itself (PrgListaDoble). The main window class (winListaDoble) allows users to add, view, search, and update employee records stored in the linked list.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

WinListaDoble package paqListaDoble; import javax.swing.JOptionPane; public class winListaDoble extends javax.swing.

JFrame { PrgListaDoble refListaDoble; NodoDoble p; public winListaDoble() { initComponents(); refListaDoble = new PrgListaDoble(); } private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) { String codi = txtCod.getText(); String nom = txtNom.getText(); char ar = txtArea.getText().charAt(0); double sue = Double.parseDouble(txtSuel.getText()); refListaDoble.agregar(codi, nom, ar, sue); txtCod.setText(""); txtNom.setText(""); txtArea.setText(""); txtSuel.setText(""); txtCod.requestFocus(); } private void btnMostrarArribaAbajoActionPerformed(java.awt.event.ActionEvent evt) { txaD.setText(""); refListaDoble.mostrarArribaAbajo(txaD); } private void txtCodMouseClicked(java.awt.event.MouseEvent evt) { txtCod.setText(""); txtNom.setText(""); txtArea.setText(""); txtSuel.setText(""); txaD.setText(""); } private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) { String cod = txtCod.getText(); p = refListaDoble.buscar(cod, txtNom, txtArea, txtSuel); } private void btnActualizarActionPerformed(java.awt.event.ActionEvent evt) { String codi = txtCod.getText(); String nom = txtNom.getText(); char are = txtArea.getText().charAt(0);

double sue = Double.parseDouble(txtSuel.getText()); p.setCodigo(codi); p.setNombre(nom); p.setArea(are); p.setSueldo(sue); JOptionPane.showMessageDialog(null, "Datos actualizados"); } private void txtCodActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } private void btnMostrarAbajoArribaActionPerformed(java.awt.event.ActionEvent evt) { txaD.setText(""); refListaDoble.mostrarAbajoArriba(txaD); }

public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new winListaDoble().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnActualizar; private javax.swing.JButton btnConsultar; private javax.swing.JButton btnGuardar; private javax.swing.JButton btnMostrarAbajoArriba; private javax.swing.JButton btnMostrarArribaAbajo; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextArea txaD; private javax.swing.JTextField txtArea; private javax.swing.JTextField txtCod; private javax.swing.JTextField txtNom; private javax.swing.JTextField txtSuel; // End of variables declaration } PrgListaDoble ackage paqListaDoble; import javax.swing.*;

public class PrgListaDoble { NodoDoble ini, fin; public PrgListaDoble() { ini = fin = null; } void agregar(String cod,String nom, char ar, double sue) { NodoDoble nuevo = new NodoDoble (cod,nom,ar,sue); if(ini==null) { ini = fin = nuevo; nuevo.sgte = null; nuevo.ant = null; } else { fin.sgte = nuevo; nuevo.ant = fin; fin = nuevo; nuevo.sgte = null; } } void mostrarArribaAbajo(JTextArea txaD) { NodoDoble aux = ini; txaD.setText("LISTADO DE DATOS ARRIBA - ABAJO\n\n"); txaD.append("Codigo"+"\t"+"Nombre"+ "\t\t"+ "Area"+ "\t"+ "Sueldo\n"); txaD.append("=====================================================\n"); while(aux != null) { txaD.append( aux.getCodigo()+"\t"+ aux.getNombre()+ "\t\t"+ aux.getArea()+ "\t"+ aux.getSueldo() + "\n"); aux = aux.sgte; } } void mostrarAbajoArriba(JTextArea txaD) { NodoDoble aux = fin; txaD.setText("LISTADO DE DATOS ABAJO - ARRIBA \n\n"); txaD.append("Codigo"+"\t"+"Nombre"+ "\t\t"+ "Area"+ "\t"+ "Sueldo\n");

txaD.append("=====================================================\n"); while(aux != null) { txaD.append( aux.getCodigo()+"\t"+ aux.getNombre()+ "\t\t"+ aux.getArea()+ "\t"+ aux.getSueldo() + "\n"); aux = aux.ant; } } NodoDoble buscar(String cod, JTextField txtNom, JTextField txtArea, JTextField txtSuel) { NodoDoble aux = ini; while(aux != null) { if(aux.getCodigo().equals(cod)) { txtNom.setText(aux.getNombre()); txtArea.setText(""+ aux.getArea()); txtSuel.setText(""+ aux.getSueldo()); return aux; } aux = aux.sgte; } JOptionPane.showMessageDialog(null, cod+", No existe"); return null; }

} NodoDoble package paqListaDoble;

public class NodoDoble { private String codigo; private String Nombre; char Area; private double Sueldo; NodoDoble sgte, ant;

public NodoDoble(String codi, String nom, char ar, double suel) { codigo = codi; Nombre = nom; Area = ar; Sueldo = suel;

} /** * @return the codigo */ public String getCodigo() { return codigo; } /** * @param codigo the codigo to set */ public void setCodigo(String codigo) { this.codigo = codigo; } /** * @return the Nombre */ public String getNombre() { return Nombre; } public void setNombre(String Nombre) { this.Nombre = Nombre; } public char getArea() { return Area; } public void setArea(char ar) { this.Area = ar; } /** * @return the Sueldo */ public double getSueldo() { return Sueldo; } /** * @param Sueldo the Sueldo to set */ public void setSueldo(double Sueldo) { this.Sueldo = Sueldo; } }

Nodos public void consultar(String codi,JTextField txtNom, JTextField txtSue) { Nodo aux = buscar(codi); if(aux != null) { txtNom.setText(aux.getNombre()); txtSue.setText(""+aux.getSueldo()); }else JOptionPane.showMessageDialog(null, codi+ "no existe"); } public Nodo buscar(String codi) { Nodo aux = ini; while(aux != null) { if(codi.equals(aux.getCodigo())) return aux; aux = aux.sgte; } return null; } void elimPrimero() { Nodo aux = ini; String nom = aux.getNombre(); ini = ini.sgte; aux.sgte = null; JOptionPane.showMessageDialog(null,nom+ ", ya esta eliminado(a)"); } void elimUltimo() { Nodo back = getBack(fin); fin = back; fin.sgte = null; } Nodo getBack(Nodo punt) { Nodo aux = ini; while(aux.sgte != punt) aux = aux.sgte; String nom = punt.getNombre(); JOptionPane.showMessageDialog(null,nom+ ", ultimo nodo eliminado"); return aux; }

You might also like