Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mx.jdr80.nomina;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import javax.swing.JFileChooser;
- import javax.swing.JOptionPane;
- /**
- *
- * @author dario
- */
- public class frmEmpleado extends javax.swing.JFrame {
- /**
- * Creates new form frmEmpleado
- */
- public frmEmpleado() {
- initComponents();
- }
- /**
- * 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.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel2 = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- txtaArchivo = new javax.swing.JTextArea();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- btnLoad = new javax.swing.JButton();
- jLabel3 = new javax.swing.JLabel();
- txtIdEmpleado = new javax.swing.JTextField();
- txtNombre = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- txtRFC = new javax.swing.JTextField();
- jLabel5 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setBackground(new java.awt.Color(153, 153, 255));
- jPanel2.setBackground(new java.awt.Color(20, 54, 66));
- txtaArchivo.setColumns(20);
- txtaArchivo.setForeground(new java.awt.Color(0, 0, 0));
- txtaArchivo.setRows(5);
- 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
- jScrollPane1.setViewportView(txtaArchivo);
- jLabel1.setFont(new java.awt.Font("Montserrat ExtraBold", 0, 36)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(255, 255, 255));
- jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
- jLabel1.setText("Nómina");
- jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mx/jdr80/nomina/imgs/icons8_form_100px.png"))); // NOI18N
- btnLoad.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mx/jdr80/nomina/imgs/icons8_opened_folder_50px.png"))); // NOI18N
- btnLoad.setText("Load File");
- btnLoad.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
- btnLoad.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
- btnLoad.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnLoadActionPerformed(evt);
- }
- });
- jLabel3.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
- jLabel3.setForeground(new java.awt.Color(255, 255, 255));
- jLabel3.setText("Número de empleado:");
- txtIdEmpleado.setBackground(new java.awt.Color(255, 255, 255));
- txtIdEmpleado.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
- txtIdEmpleado.setForeground(new java.awt.Color(0, 0, 0));
- txtIdEmpleado.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtIdEmpleadoActionPerformed(evt);
- }
- });
- txtNombre.setBackground(new java.awt.Color(255, 255, 255));
- txtNombre.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
- txtNombre.setForeground(new java.awt.Color(0, 0, 0));
- txtNombre.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtNombreActionPerformed(evt);
- }
- });
- jLabel4.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
- jLabel4.setForeground(new java.awt.Color(255, 255, 255));
- jLabel4.setText("Nombre del empleado:");
- txtRFC.setBackground(new java.awt.Color(255, 255, 255));
- txtRFC.setFont(new java.awt.Font("Montserrat Light", 0, 12)); // NOI18N
- txtRFC.setForeground(new java.awt.Color(0, 0, 0));
- txtRFC.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtRFCActionPerformed(evt);
- }
- });
- jLabel5.setFont(new java.awt.Font("Montserrat Black", 0, 14)); // NOI18N
- jLabel5.setForeground(new java.awt.Color(255, 255, 255));
- jLabel5.setText("R.F.C del empleado:");
- javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
- jPanel2.setLayout(jPanel2Layout);
- jPanel2Layout.setHorizontalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
- .addGap(32, 32, 32)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jLabel4)
- .addComponent(jLabel5)
- .addComponent(jLabel3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(txtRFC)
- .addComponent(txtNombre)
- .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(18, 18, 18)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(btnLoad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(20, 20, 20))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jLabel2)
- .addGap(14, 14, 14))))
- );
- jPanel2Layout.setVerticalGroup(
- jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel2))
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGap(39, 39, 39)
- .addComponent(jLabel1)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGroup(jPanel2Layout.createSequentialGroup()
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel3)
- .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel4)
- .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel5)
- .addComponent(txtRFC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(btnLoad)
- .addGap(38, 38, 38))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void btnLoadActionPerformed(java.awt.event.ActionEvent evt) {
- // se usa la clase JFileChooser para poder seleccionar el archivo
- JFileChooser fc= new JFileChooser();//creacion del objeto de la clase JFileChooser
- fc.showOpenDialog(null);//abriendo la ventana de dialogo para la seleccion del archivo
- 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
- //como el metodo FileReader lanza una exepcion, es necesario meterlo en un try catch
- try {
- //creando el objeto de la clase FileReader y pasandole por paramentro el objeto de la clase file archivo
- FileReader fr= new FileReader(archivo);
- //creando el objeto br de la clase BufferedReader para almacenar en el buffer el archivo seleccionado, que es pasado por paramentro
- BufferedReader br = new BufferedReader(fr);
- //creacion de variables que contendran el texto del archivo leeido
- String texto="";
- String linea="";
- //bucle para leer el archivo
- while(((linea=br.readLine())!=null)){ //mientras que lo devuelto por el buffer no sea vacio
- texto+=linea+"\n"; //se le suma a la variable texto lo contendido en la variable linea
- }
- //escribiendo en el area de texto designada el contenido de el archivo
- txtaArchivo.setText(texto);
- //se muestra en pantalla el aviso de que el archivo fue cargado de manera exitosa
- JOptionPane.showMessageDialog(null, "Archivo cargado exitosamente ");
- //cerrando el stream fr
- fr.close();
- } catch (Exception e) {
- //mostrando la exepcion en caso de error
- JOptionPane.showMessageDialog(null, "Error al cargar archivo", "Error", JOptionPane.ERROR_MESSAGE);
- }
- }
- private void txtIdEmpleadoActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txtRFCActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- /**
- * @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(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(frmEmpleado.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(frmEmpleado.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 frmEmpleado().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnLoad;
- 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.JPanel jPanel2;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTextField txtIdEmpleado;
- private javax.swing.JTextField txtNombre;
- private javax.swing.JTextField txtRFC;
- private javax.swing.JTextArea txtaArchivo;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement