Advertisement
Irlan

jifLista

Apr 4th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.40 KB | None | 0 0
  1. package Interface;
  2.  
  3. import Connection.AutorDAO;
  4. import Model.Autor;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.List;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.table.DefaultTableModel;
  10.  
  11. /**
  12.  *
  13.  * @author IrlanJR
  14.  */
  15. public class jifLista extends javax.swing.JInternalFrame {
  16.  
  17.     DefaultTableModel tbLogs = new DefaultTableModel(null, new String[]{"Cรณdigo", "Nome", "Nascimento"});
  18.     AutorDAO autorDAO = new AutorDAO();
  19.    
  20.     public jifLista() {
  21.         initComponents();
  22.         jTbTeste.setModel(tbLogs);
  23.        
  24.     }
  25.  
  26.     /**
  27.      * This method is called from within the constructor to initialize the form.
  28.      * WARNING: Do NOT modify this code. The content of this method is always
  29.      * regenerated by the Form Editor.
  30.      */
  31.     @SuppressWarnings("unchecked")
  32.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  33.     private void initComponents() {
  34.  
  35.         jScrollPane1 = new javax.swing.JScrollPane();
  36.         jTbTeste = new javax.swing.JTable();
  37.         jButton1 = new javax.swing.JButton();
  38.         jButton2 = new javax.swing.JButton();
  39.         tfPesquisar = new javax.swing.JTextField();
  40.  
  41.         setClosable(true);
  42.         setResizable(true);
  43.         try {
  44.             setSelected(true);
  45.         } catch (java.beans.PropertyVetoException e1) {
  46.             e1.printStackTrace();
  47.         }
  48.         setVisible(true);
  49.         addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
  50.             public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
  51.             }
  52.             public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
  53.             }
  54.             public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
  55.             }
  56.             public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
  57.             }
  58.             public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
  59.             }
  60.             public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
  61.             }
  62.             public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
  63.                 formInternalFrameOpened(evt);
  64.             }
  65.         });
  66.  
  67.         jTbTeste.setModel(new javax.swing.table.DefaultTableModel(
  68.             new Object [][] {
  69.                 {},
  70.                 {},
  71.                 {},
  72.                 {}
  73.             },
  74.             new String [] {
  75.  
  76.             }
  77.         ));
  78.         jScrollPane1.setViewportView(jTbTeste);
  79.  
  80.         jButton1.setText("Selecionar");
  81.  
  82.         jButton2.setText("Cancelar");
  83.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  84.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  85.                 jButton2ActionPerformed(evt);
  86.             }
  87.         });
  88.  
  89.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  90.         getContentPane().setLayout(layout);
  91.         layout.setHorizontalGroup(
  92.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.             .addGroup(layout.createSequentialGroup()
  94.                 .addContainerGap()
  95.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  96.                     .addGroup(layout.createSequentialGroup()
  97.                         .addComponent(tfPesquisar)
  98.                         .addContainerGap())
  99.                     .addGroup(layout.createSequentialGroup()
  100.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
  101.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  102.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103.                             .addGroup(layout.createSequentialGroup()
  104.                                 .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  105.                                 .addGap(12, 12, 12))
  106.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  107.                                 .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
  108.                                 .addContainerGap())))))
  109.         );
  110.         layout.setVerticalGroup(
  111.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  112.             .addGroup(layout.createSequentialGroup()
  113.                 .addContainerGap()
  114.                 .addComponent(tfPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  115.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  116.                     .addGroup(layout.createSequentialGroup()
  117.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  118.                         .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
  119.                     .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  120.                         .addGap(22, 22, 22)
  121.                         .addComponent(jButton1)
  122.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  123.                         .addComponent(jButton2)))
  124.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  125.         );
  126.  
  127.         pack();
  128.     }// </editor-fold>                        
  129.  
  130.     private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {                                        
  131.        
  132.         preencherTabela();
  133.        
  134.     }                                        
  135.  
  136.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  137.         // TODO add your handling code here:
  138.     }                                        
  139.  
  140.  
  141.     // Variables declaration - do not modify                    
  142.     private javax.swing.JButton jButton1;
  143.     private javax.swing.JButton jButton2;
  144.     private javax.swing.JScrollPane jScrollPane1;
  145.     public javax.swing.JTable jTbTeste;
  146.     private javax.swing.JTextField tfPesquisar;
  147.     // End of variables declaration                  
  148.  
  149.    
  150.     public void exibirAutores(List<Autor> list){
  151.            
  152.         list = autorDAO.acharTodos();
  153.        
  154.         while (tbLogs.getRowCount() > 0) {
  155.             tbLogs.removeRow(0);
  156.         }
  157.         try {
  158.             String[] linhas = new String[]{null, null, null};
  159.             for (int i = 0; i < list.size(); i++) {
  160.                
  161.                 tbLogs.addRow(linhas);
  162.                 tbLogs.setValueAt(list.get(i).getCod(), i, 0);
  163.                 tbLogs.setValueAt(list.get(i).getNome(), i, 1);
  164.                 tbLogs.setValueAt(list.get(i).getDataNasc(), i, 2);
  165.                
  166.             }
  167.  
  168.         } catch (Exception e) {
  169.             JOptionPane.showMessageDialog(null, "Erro ao listar pessoas!; " + e);
  170.         }
  171.            
  172.        
  173.     }
  174.    
  175.     public void preencherTabela(){
  176.        
  177.         List<Autor>  list = autorDAO.acharTodos();
  178.        
  179.         exibirAutores(list);
  180.        
  181.        
  182.     }
  183.    
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement