Utilización de Swing y Vector Con Netbeans 7.3
Utilización de Swing y Vector Con Netbeans 7.3
Utilización de Swing y Vector Con Netbeans 7.3
TELECOMUNICACIONES
TRABAJO DE JAVA ESTNDAR EDITION USO DE SWING Y VECTOR EN JAVA DEL PAQUETE UTILS
OBJETIVO Desarrollar las habilidades para la manipulacin de datos en memoria por medio de vector y swing basados en el uso de java.utils. Tender al Uso del IDE Netbeans 7.3 para el desarrollo profesional de aplicativos en JAVA.
El cdigo Fuente que Implementa dicho ejercicio de manejo de Programa para hallar la nmina de los empleados de la empresa Tecnisoft de la costa. Requisitos: Lenguaje de programacin JAVA. Caso de Uso Se pide al usuario ingresar el nombre, sexo, nmero de horas de trabajo y el sueldo por hora para cada uno de los empleados. La primera parte de la salida debe dar el nombre y el pago para cada empleado; en este caso mostramos esas funciones cada una en un tab del aplicativo. La segunda parte debe dar totales separados y pagos promedios separados para hombres y para mujeres. El programa puede suponer que hay al menos un empleado de cada sexo.
Desarrollo del Codigo Fuente /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package datosempleados; import java.util.Vector;
import javax.swing.JOptionPane; /** * * @author LENOVO */ public class jformdatosemp extends javax.swing.JFrame { Vector l1,l2,l3,l4,l9; /** * Creates new form jformdatosemp */ public jformdatosemp() { initComponents(); l1=new Vector();//nombre del trabajador l2=new Vector();//sexo l3=new Vector();//numero de horas l4=new Vector();//valor l9=new Vector();//para el metodo puntitos jTextArea1.setVisible(false); //para el metodo puntitos
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */
jTabbedPane1 = new javax.swing.JTabbedPane(); jInternalFrame1 = new javax.swing.JInternalFrame(); jLabel1 = new javax.swing.JLabel(); jTextField1 = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jTextField2 = new javax.swing.JTextField(); jComboBox1 = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jTextField3 = new javax.swing.JTextField(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jButton2 = new javax.swing.JButton(); jInternalFrame2 = new javax.swing.JInternalFrame(); jScrollPane2 = new javax.swing.JScrollPane(); jTextArea2 = new javax.swing.JTextArea(); jButton4 = new javax.swing.JButton(); jInternalFrame3 = new javax.swing.JInternalFrame(); jScrollPane3 = new javax.swing.JScrollPane(); jTextArea3 = new javax.swing.JTextArea(); jLabel5 = new javax.swing.JLabel();
jTextField4 = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); jTextField5 = new javax.swing.JTextField(); jComboBox2 = new javax.swing.JComboBox(); jButton3 = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jInternalFrame1.setFrameIcon(null); jInternalFrame1.setVisible(true);
jLabel1.setText("Nombre");
jTextField1.setText("--");
jLabel2.setText("Sexo");
jTextField2.setText("0");
jScrollPane1.setFocusable(false);
jButton2.setText("Limpiar");
javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane()); jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout); jInternalFrame1Layout.setHorizontalGroup( jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addContainerGap() .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3)) .addGap(28, 28, 28) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addComponent(jComboBox1, 0, 184, Short.MAX_VALUE) .addComponent(jTextField2) .addComponent(jTextField3) .addComponent(jTextField1)) .addGap(34, 34, 34)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addComponent(jLabel4) .addGap(18, 18, 18)))) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGap(72, 72, 72) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) ); jInternalFrame1Layout.setVerticalGroup( jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addGap(19, 19, 19) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jLabel1)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(jInternalFrame1Layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(18, 18, 18) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(12, 12, 12) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel3)) .addGap(24, 24, 24) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING, false) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(27, Short.MAX_VALUE)) );
jInternalFrame2.setFrameIcon(null); jInternalFrame2.setVisible(true);
});
javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane()); jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout); jInternalFrame2Layout.setHorizontalGroup( jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addContainerGap() .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton4)) .addContainerGap(27, Short.MAX_VALUE)) ); jInternalFrame2Layout.setVerticalGroup( jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame2Layout.createSequentialGroup() .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
jInternalFrame3.setFrameIcon(null); jInternalFrame3.setVisible(true);
jLabel5.setText("pago total");
jTextField4.setText("0");
jLabel6.setText("promedio");
jTextField5.setText("0");
jLabel7.setText("Seleccione el Sexo");
javax.swing.GroupLayout jInternalFrame3Layout = new javax.swing.GroupLayout(jInternalFrame3.getContentPane()); jInternalFrame3.getContentPane().setLayout(jInternalFrame3Layout); jInternalFrame3Layout.setHorizontalGroup( jInternalFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame3Layout.createSequentialGroup() .addContainerGap() .addGroup(jInternalFrame3Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 342, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jInternalFrame3Layout.createSequentialGroup() .addComponent(jLabel5) .addGap(39, 39, 39) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jInternalFrame3Layout.createSequentialGroup() .addComponent(jLabel7) .addGap(18, 18, 18) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3))) .addContainerGap(20, Short.MAX_VALUE)) ); jInternalFrame3Layout.setVerticalGroup( jInternalFrame3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment .LEADING) .addGroup(jInternalFrame3Layout.createSequentialGroup() .addContainerGap() .addGroup(jInternalFrame3Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton3) .addComponent(jLabel7))
.addGap(18, 18, 18) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(jInternalFrame3Layout.createParallelGroup(javax.swing.GroupLayou t.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6) .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) );
private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) { jTextField3.setText(puntos(jTextField3.getText())); try{ int s=Integer.parseInt(jTextField3.getText().replace(".","")); }catch(Exception rtg){ JOptionPane.showMessageDialog(null,rtg); } }
private void jTextField2KeyReleased(java.awt.event.KeyEvent evt) { jTextField2.setText(puntos(jTextField2.getText())); try{ int s=Integer.parseInt(jTextField2.getText().replace(".","")); }catch(Exception rtg){ JOptionPane.showMessageDialog(null,rtg); } }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { try{ //meter en los vectores //nombre de los trabajadores l1.add(new String(jTextField1.getText())); //lista el sexo l2.add(new String(jComboBox1.getSelectedItem().toString())); JOptionPane.showMessageDialog(rootPane,l2.get(0).toString()); //lista de los numeros de horas trab. l3.add(new Integer(jTextField2.getText().replace(".",""))); //lista de las valor de las horas trabajadas l4.add(new Integer(jTextField3.getText().replace(".",""))); }catch(Exception rtg){ JOptionPane.showMessageDialog(null,rtg); }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { //se manda 1 para cuando el sistema necesita el reporte de todos los datos ingreados en los vectores mostrar_arreglos_datos_trabajadores(1,"nada"); }
JOptionPane.showMessageDialog(rootPane, jComboBox2.getItemAt(jComboBox2.getSelectedIndex()).toString()); mostrar_arreglos_datos_trabajadores(2,jComboBox2.getItemAt(jComboBox2.ge tSelectedIndex()).toString()); } public String puntos(String dato){ try{ int z=0; l9.removeAllElements(); String texto = new String(); { jTextArea1.setText(""); texto=dato.replace(".", ""); int a=texto.length(); for(int y=0;y<a;y++ ){ if(a==4 && y==1){ l9.add(new String(".")); texto.concat("."); } if(a==8 && y==2){ l9.add(new String(".")); } if(a==5 && y==2){ l9.add(new String(".")); } if(a==6 && y==3){ l9.add(new String("."));
} if(a==8 && y==5){ l9.add(new String(".")); } if(a==7 && y==1){ l9.add(new String(".")); } if(a==7 && z==4){ l9.add(new String(".")); } l9.add(new String(texto.substring(z,z+1))); if(z<a) z++; }
public void mostrar_arreglos_datos_trabajadores(int bandera, String textobuscar){ jTextArea2.setText(""); int contadorban=0; float subtotal=0; float promedio=0; //debemos limpiar la vista en el formulario de los datos y nuevamente mostarlos, pero los datos originales estan //en los vectores de objetos, esto solo muestra los vectores llenos //ahora muestro los datos de los vectores for(int a=0;a<l1.size();a++){ //el reporte se muestra sobre un jtextarea if(bandera==1){ jTextArea2.append(l1.get(a).toString()+"\t|" +l2.get(a).toString() +"\t|"+l3.get(a).toString() +"\t|"+l4.get(a).toString() +"\t|"+Integer.parseInt(l3.get(a).toString())*Integer.parseInt(l4.get(a).toString() )+"\t|\n"); } if(bandera==2 && l2.get(a).toString().equals(textobuscar)){ contadorban++; jTextArea3.append(l1.get(a).toString()+"\t|" +l2.get(a).toString() +"\t|"+l3.get(a).toString() +"\t|"+l4.get(a).toString()
} } jTextField4.setText(""+subtotal); promedio=subtotal/contadorban; jTextField5.setText(""+promedio); } /** * @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(jformdatosemp.class.getName()).log(java.uti l.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(jformdatosemp.class.getName()).log(java.uti l.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(jformdatosemp.class.getName()).log(java.uti l.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(jformdatosemp.class.getName()).log(java.uti l.logging.Level.SEVERE, null, ex); } //</editor-fold>
/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new jformdatosemp().setVisible(true); } }); } // Variables declaration - do not modify
private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JInternalFrame jInternalFrame1; private javax.swing.JInternalFrame jInternalFrame2; private javax.swing.JInternalFrame jInternalFrame3; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextArea jTextArea2; private javax.swing.JTextArea jTextArea3; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JTextField jTextField3;