Lista trabajador

296 views
161 views

Published on

listas

Published in: Technology, Art & Photos
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
296
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lista trabajador

  1. 1. package Lista; publicclassListaTrabajador { private Trabajador p=null; privateclass Trabajador{ private String dni; private String nombre; private String apellido; privateintdias; privatedoublejornaldia; Trabajador siguiente; private double calcularsueldo(){ returnjornaldia*dias; } } public void agregar(double j, String d, String n, String a, int di){ ListaTrabajador.Trabajador q=new ListaTrabajador.Trabajador(); q.dni=d; q.nombre=n; q.apellido=a; q.dias=di; q.jornaldia=j;
  2. 2. q.siguiente=p; p=q; } publicStringmostrarnombre(){ ListaTrabajador.Trabajador q=p; String valor=""; while(q!=null) { valor=valor+q.nombre+" "+q.apellido+"n"; q=q.siguiente; } return valor; } publicStringmostrardias(){ ListaTrabajador.Trabajador q=p; String valor=""; while(q!=null) { valor=valor+q.dias+"n"; q=q.siguiente; } return valor; } publicStringmostrarjornal(){
  3. 3. ListaTrabajador.Trabajador q=p; String valor=""; while(q!=null) { valor=valor+q.jornaldia+"n"; q=q.siguiente; } return valor; } publicStringmostrarsueldo(){ ListaTrabajador.Trabajador q=p; String valor=""; while(q!=null) { valor=valor+q.calcularsueldo()+"n"; q=q.siguiente; } return valor; } } FRM package Prueba; importLista.ListaTrabajador;
  4. 4. importLista.Listasimple; importjavax.swing.JOptionPane; publicclassfrmlistatrabajadorextendsjavax.swing.JFrame { publicListaTrabajadorlst=new ListaTrabajador(); publicfrmlistatrabajador() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); btnnuevo = new javax.swing.JButton(); btnagregar = new javax.swing.JButton(); btnmostrar = new javax.swing.JButton(); btnsalir = new javax.swing.JButton(); txtdni = new javax.swing.JTextField(); txtnombre = new javax.swing.JTextField(); txtapellido = new javax.swing.JTextField(); txtdias = new javax.swing.JTextField();
  5. 5. txtjornal = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); txtarea = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); txtarea1 = new javax.swing.JTextArea(); jScrollPane3 = new javax.swing.JScrollPane(); txtarea2 = new javax.swing.JTextArea(); jScrollPane4 = new javax.swing.JScrollPane(); txtarea3 = new javax.swing.JTextArea(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); jLabel1.setText("DNI"); getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 14, -1, -1)); jLabel2.setText("NOMBRES"); getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 57, -1, -1)); jLabel3.setText("APELLIDOS"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 97, -1, -1));
  6. 6. jLabel4.setText("DIAS TRABAJADOS"); getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 137, -1, 1)); jLabel5.setText("JORNAL DEL DIA"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 177, -1, 1)); btnnuevo.setText("NUEVO"); btnnuevo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { btnnuevoActionPerformed(evt); } }); getContentPane().add(btnnuevo, new org.netbeans.lib.awtextra.AbsoluteConstraints(42, 229, -1, 1)); btnagregar.setText("AGREGAR"); btnagregar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { btnagregarActionPerformed(evt); } }); getContentPane().add(btnagregar, new org.netbeans.lib.awtextra.AbsoluteConstraints(178, 229, 1, -1)); btnmostrar.setText("MOSTRAR");
  7. 7. btnmostrar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { btnmostrarActionPerformed(evt); } }); getContentPane().add(btnmostrar, new org.netbeans.lib.awtextra.AbsoluteConstraints(315, 229, 1, -1)); btnsalir.setText("SALIR"); btnsalir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { btnsalirActionPerformed(evt); } }); getContentPane().add(btnsalir, new org.netbeans.lib.awtextra.AbsoluteConstraints(466, 229, -1, 1)); getContentPane().add(txtdni, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 130, 30)); txtnombre.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { txtnombreActionPerformed(evt); } }); getContentPane().add(txtnombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 50, 350, 30));
  8. 8. getContentPane().add(txtapellido, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 90, 350, 30)); getContentPane().add(txtdias, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 130, 130, 30)); txtjornal.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEventevt) { txtjornalActionPerformed(evt); } }); getContentPane().add(txtjornal, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 170, 130, 30)); txtarea.setColumns(20); txtarea.setRows(5); jScrollPane1.setViewportView(txtarea); getContentPane().add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(24, 295, 181, -1)); txtarea1.setColumns(20); txtarea1.setRows(5); jScrollPane2.setViewportView(txtarea1); getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 295, 106, -1));
  9. 9. txtarea2.setColumns(20); txtarea2.setRows(5); jScrollPane3.setViewportView(txtarea2); getContentPane().add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(344, 295, 96, -1)); txtarea3.setColumns(20); txtarea3.setRows(5); jScrollPane4.setViewportView(txtarea3); getContentPane().add(jScrollPane4, new org.netbeans.lib.awtextra.AbsoluteConstraints(466, 295, 103, -1)); jLabel6.setText("DIAS TRAB"); getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(230, 270, -1, 1)); jLabel7.setText("JORNAL DIA"); getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(356, 270, -1, 1)); jLabel8.setText("SUELDO"); getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(472, 270, -1, 1)); jLabel9.setText("NOMBRES Y APELLIDOS");
  10. 10. getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(33, 270, -1, 1)); pack(); }// </editor-fold> private void txtjornalActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: } private void txtnombreActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: } private void btnagregarActionPerformed(java.awt.event.ActionEventevt) { String d, a, n; int di; double jo; d=txtdni.getText(); n=txtnombre.getText(); a=txtapellido.getText(); di=Integer.parseInt(txtdias.getText()); jo=Double.parseDouble(txtjornal.getText()); lst.agregar(jo, d, n, a, di); }
  11. 11. private void btnmostrarActionPerformed(java.awt.event.ActionEventevt) { txtarea.append(lst.mostrarnombre()); txtarea1.append(lst.mostrardias()); txtarea2.append(lst.mostrarjornal()); txtarea3.append(lst.mostrarsueldo()); } private void btnsalirActionPerformed(java.awt.event.ActionEventevt) { int x=JOptionPane.showConfirmDialog(rootPane, "DeseaSalir", "Salir", JOptionPane.INFORMATION_MESSAGE); if(x==0) System.exit(0); } private void btnnuevoActionPerformed(java.awt.event.ActionEventevt) { txtdni.setText("") ; txtnombre.setText("") ; txtapellido.setText("") ; txtdias.setText("") ; txtjornal.setText("") ; txtarea.setText("") ; txtarea1.setText("") ; txtarea2.setText("") ; txtarea3.setText("") ; }
  12. 12. /** * @paramargs 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(frmlistatrabajador.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(frmlistatrabajador.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (IllegalAccessException ex) {
  13. 13. java.util.logging.Logger.getLogger(frmlistatrabajador.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(frmlistatrabajador.class.getName()).log(java.util.logging.Level.SE VERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new frmlistatrabajador().setVisible(true); } }); }

×