Advertisement
Metziop

frmEmpleados(java)

Apr 13th, 2021
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.21 KB | None | 0 0
  1. package mx.jdr80.nomina;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import javax.swing.JFileChooser;
  7. import javax.swing.JOptionPane;
  8.  
  9. /**
  10.  *
  11.  * @author dario
  12.  */
  13. public class frmEmpleado extends javax.swing.JFrame {
  14.  
  15.     /**
  16.      * Creates new form frmEmpleado
  17.      */
  18.     public frmEmpleado() {
  19.         initComponents();
  20.     }
  21.  
  22.     /**
  23.      * This method is called from within the constructor to initialize the form.
  24.      * WARNING: Do NOT modify this code. The content of this method is always
  25.      * regenerated by the Form Editor.
  26.      */
  27.     @SuppressWarnings("unchecked")
  28.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  29.     private void initComponents() {
  30.  
  31.         jPanel2 = new javax.swing.JPanel();
  32.         jScrollPane1 = new javax.swing.JScrollPane();
  33.         txtaArchivo = new javax.swing.JTextArea();
  34.         jLabel1 = new javax.swing.JLabel();
  35.         jLabel2 = new javax.swing.JLabel();
  36.         btnLoad = new javax.swing.JButton();
  37.         jLabel3 = new javax.swing.JLabel();
  38.         txtIdEmpleado = new javax.swing.JTextField();
  39.         txtNombre = new javax.swing.JTextField();
  40.         jLabel4 = new javax.swing.JLabel();
  41.         txtRFC = new javax.swing.JTextField();
  42.         jLabel5 = new javax.swing.JLabel();
  43.  
  44.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  45.         setBackground(new java.awt.Color(153, 153, 255));
  46.  
  47.         jPanel2.setBackground(new java.awt.Color(20, 54, 66));
  48.  
  49.         txtaArchivo.setColumns(20);
  50.         txtaArchivo.setForeground(new java.awt.Color(0, 0, 0));
  51.         txtaArchivo.setRows(5);
  52.         txtaArchivo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Archivo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Montserrat ExtraLight", 0, 12), new java.awt.Color(0, 0, 0))); // NOI18N
  53.         jScrollPane1.setViewportView(txtaArchivo);
  54.  
  55.         jLabel1.setFont(new java.awt.Font("Montserrat ExtraBold", 0, 36)); // NOI18N
  56.         jLabel1.setForeground(new java.awt.Color(255, 255, 255));
  57.         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
  58.         jLabel1.setText("Nómina");
  59.  
  60.         jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mx/jdr80/nomina/imgs/icons8_form_100px.png"))); // NOI18N
  61.  
  62.         btnLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mx/jdr80/nomina/imgs/icons8_opened_folder_50px.png"))); // NOI18N
  63.         btnLoad.setText("Load File");
  64.         btnLoad.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
  65.         btnLoad.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
  66.         btnLoad.addActionListener(new java.awt.event.ActionListener() {
  67.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  68.                 btnLoadActionPerformed(evt);
  69.             }
  70.         });
  71.  
  72.         jLabel3.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
  73.         jLabel3.setForeground(new java.awt.Color(255, 255, 255));
  74.         jLabel3.setText("Número de empleado:");
  75.  
  76.         txtIdEmpleado.setBackground(new java.awt.Color(255, 255, 255));
  77.         txtIdEmpleado.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
  78.         txtIdEmpleado.setForeground(new java.awt.Color(0, 0, 0));
  79.         txtIdEmpleado.addActionListener(new java.awt.event.ActionListener() {
  80.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  81.                 txtIdEmpleadoActionPerformed(evt);
  82.             }
  83.         });
  84.  
  85.         txtNombre.setBackground(new java.awt.Color(255, 255, 255));
  86.         txtNombre.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
  87.         txtNombre.setForeground(new java.awt.Color(0, 0, 0));
  88.         txtNombre.addActionListener(new java.awt.event.ActionListener() {
  89.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  90.                 txtNombreActionPerformed(evt);
  91.             }
  92.         });
  93.  
  94.         jLabel4.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
  95.         jLabel4.setForeground(new java.awt.Color(255, 255, 255));
  96.         jLabel4.setText("Nombre del empleado:");
  97.  
  98.         txtRFC.setBackground(new java.awt.Color(255, 255, 255));
  99.         txtRFC.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
  100.         txtRFC.setForeground(new java.awt.Color(0, 0, 0));
  101.         txtRFC.addActionListener(new java.awt.event.ActionListener() {
  102.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  103.                 txtRFCActionPerformed(evt);
  104.             }
  105.         });
  106.  
  107.         jLabel5.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
  108.         jLabel5.setForeground(new java.awt.Color(255, 255, 255));
  109.         jLabel5.setText("R.F.C del empleado:");
  110.  
  111.         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
  112.         jPanel2.setLayout(jPanel2Layout);
  113.         jPanel2Layout.setHorizontalGroup(
  114.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  115.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
  116.                 .addGap(32, 32, 32)
  117.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118.                     .addComponent(jLabel4)
  119.                     .addComponent(jLabel5)
  120.                     .addComponent(jLabel3))
  121.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  122.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  123.                     .addComponent(txtRFC)
  124.                     .addComponent(txtNombre)
  125.                     .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
  126.                 .addGap(18, 18, 18)
  127.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  128.                     .addGroup(jPanel2Layout.createSequentialGroup()
  129.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.                             .addComponent(btnLoad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
  131.                             .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
  132.                         .addGap(20, 20, 20))
  133.                     .addGroup(jPanel2Layout.createSequentialGroup()
  134.                         .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
  135.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  136.                         .addComponent(jLabel2)
  137.                         .addGap(14, 14, 14))))
  138.         );
  139.         jPanel2Layout.setVerticalGroup(
  140.             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  141.             .addGroup(jPanel2Layout.createSequentialGroup()
  142.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143.                     .addGroup(jPanel2Layout.createSequentialGroup()
  144.                         .addContainerGap()
  145.                         .addComponent(jLabel2))
  146.                     .addGroup(jPanel2Layout.createSequentialGroup()
  147.                         .addGap(39, 39, 39)
  148.                         .addComponent(jLabel1)))
  149.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  150.                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  151.                     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
  152.                     .addGroup(jPanel2Layout.createSequentialGroup()
  153.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  154.                             .addComponent(jLabel3)
  155.                             .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  156.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  157.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  158.                             .addComponent(jLabel4)
  159.                             .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  160.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  161.                         .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  162.                             .addComponent(jLabel5)
  163.                             .addComponent(txtRFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
  164.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  165.                 .addComponent(btnLoad)
  166.                 .addGap(38, 38, 38))
  167.         );
  168.  
  169.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  170.         getContentPane().setLayout(layout);
  171.         layout.setHorizontalGroup(
  172.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  173.             .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  174.         );
  175.         layout.setVerticalGroup(
  176.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  177.             .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  178.         );
  179.  
  180.         pack();
  181.     }// </editor-fold>                        
  182.  
  183.     private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {                                        
  184.     // se usa la clase JFileChooser para poder seleccionar el archivo
  185.     JFileChooser fc= new JFileChooser();//creacion del objeto de la clase JFileChooser
  186.     fc.showOpenDialog(null);//abriendo la ventana de dialogo para la seleccion del archivo
  187.     File archivo =fc.getSelectedFile();//creando el objeto de la clase File y se le pasa lo que tiene el objeto filechooser con el metodo getSelectedFile
  188.         //como el metodo FileReader lanza una exepcion, es necesario meterlo en un try catch
  189.         try {
  190.             //creando el objeto de la clase FileReader y pasandole por paramentro el objeto de la clase file archivo
  191.             FileReader fr= new FileReader(archivo);
  192.             //creando el objeto br de la clase BufferedReader para almacenar en el buffer el archivo seleccionado, que es pasado por paramentro
  193.             BufferedReader br = new BufferedReader(fr);
  194.             //creacion de variables que contendran el texto del archivo leeido
  195.             String texto="";
  196.             String linea="";
  197.             //bucle para leer el archivo
  198.             while(((linea=br.readLine())!=null)){ //mientras que lo devuelto por el buffer no sea vacio
  199.                 texto+=linea+"\n"; //se le suma a la variable texto lo contendido en la variable linea
  200.             }
  201.             //escribiendo en el area de texto designada el contenido de el archivo
  202.             txtaArchivo.setText(texto);
  203.             //se muestra en pantalla el aviso de que el archivo fue cargado de manera exitosa
  204.             JOptionPane.showMessageDialog(null, "Archivo cargado exitosamente ");
  205.             //cerrando el stream fr
  206.             fr.close();
  207.            
  208.         } catch (Exception e) {
  209.             //mostrando la exepcion en caso de error
  210.           JOptionPane.showMessageDialog(null, "Error al cargar archivo", "Error", JOptionPane.ERROR_MESSAGE);
  211.         }
  212.    
  213.    
  214.        
  215.    
  216.    
  217.     }                                      
  218.  
  219.     private void txtIdEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {                                              
  220.         // TODO add your handling code here:
  221.     }                                            
  222.  
  223.     private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {                                          
  224.         // TODO add your handling code here:
  225.     }                                        
  226.  
  227.     private void txtRFCActionPerformed(java.awt.event.ActionEvent evt) {                                      
  228.         // TODO add your handling code here:
  229.     }                                      
  230.  
  231.     /**
  232.      * @param args the command line arguments
  233.      */
  234.     public static void main(String args[]) {
  235.         /* Set the Nimbus look and feel */
  236.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  237.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  238.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  239.          */
  240.         try {
  241.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  242.                 if ("Nimbus".equals(info.getName())) {
  243.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  244.                     break;
  245.                 }
  246.             }
  247.         } catch (ClassNotFoundException ex) {
  248.             java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  249.         } catch (InstantiationException ex) {
  250.             java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  251.         } catch (IllegalAccessException ex) {
  252.             java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  253.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  254.             java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  255.         }
  256.         //</editor-fold>
  257.  
  258.         /* Create and display the form */
  259.         java.awt.EventQueue.invokeLater(new Runnable() {
  260.             public void run() {
  261.                 new frmEmpleado().setVisible(true);
  262.             }
  263.         });
  264.     }
  265.  
  266.     // Variables declaration - do not modify                    
  267.     private javax.swing.JButton btnLoad;
  268.     private javax.swing.JLabel jLabel1;
  269.     private javax.swing.JLabel jLabel2;
  270.     private javax.swing.JLabel jLabel3;
  271.     private javax.swing.JLabel jLabel4;
  272.     private javax.swing.JLabel jLabel5;
  273.     private javax.swing.JPanel jPanel2;
  274.     private javax.swing.JScrollPane jScrollPane1;
  275.     private javax.swing.JTextField txtIdEmpleado;
  276.     private javax.swing.JTextField txtNombre;
  277.     private javax.swing.JTextField txtRFC;
  278.     private javax.swing.JTextArea txtaArchivo;
  279.     // End of variables declaration                  
  280. }
  281.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement