Guest User

Untitled

a guest
Sep 14th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.25 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in th
  4.  
  5.             @Override
  6.             public int getRowCount() {
  7.                 throw new UnsupportedOperationException("Not supported yet.");
  8.             }
  9.  
  10.             @Override
  11.             public int getColumnCount() {
  12.                 throw new UnsupportedOperationException("Not supported yet.");
  13.             }
  14.  
  15.             @Override
  16.             public String getColumnName(int i) {
  17.                 throw new UnsupportedOperationException("Not supported yet.");
  18.             }
  19.  
  20.             @Override
  21.             public Class<?> getColumnClass(int i) {
  22.                 throw new UnsupportedOperationException("Not supported yet.");
  23.             }
  24.  
  25.             @Override
  26.             public boolean isCellEditable(int i, int i1) {
  27.                 throw new UnsupportedOperationException("Not supported yet.");
  28.             }
  29.  
  30.             @Override
  31.             public Object getValueAt(int i, int i1) {
  32.                 throw new UnsupportedOperationException("Not supported yet.");
  33.             }
  34.  
  35.             @Override
  36.             public void setValueAt(Object o, int i, int i1) {
  37.                 throw new UnsupportedOperationException("Not supported yet.");
  38.             }
  39.  
  40.             @Override
  41.             public void addTableModelListener(TableModelListener tl) {
  42.                 throw new UnsupportedOperationException("Not supported yet.");
  43.             }
  44.  
  45.             @Override
  46.             public void removeTableModelListener(TableModelListener tl) {
  47.                 throw new UnsupportedOperationException("Not supported yet.");
  48.             }
  49.         } editor.
  50.  */
  51. package guitest;
  52.  
  53. import java.awt.BorderLayout;
  54. import java.sql.SQLException;
  55. import java.util.logging.Level;
  56. import java.util.logging.Logger;
  57. import javax.swing.JScrollPane;
  58. import javax.swing.JTable;
  59. import javax.swing.event.TableModelEvent;
  60. import javax.swing.event.TableModelListener;
  61. import javax.swing.table.AbstractTableModel;
  62. import javax.swing.table.DefaultTableModel;
  63.  
  64. /**
  65.  *
  66.  * @author Malmo
  67.  */
  68. public class SauGUI extends javax.swing.JFrame  {
  69.  
  70.     /**
  71.      * Creates new form SauGUI
  72.      */
  73.    
  74.     private SauDatabase db = new SauDatabase();
  75.     private DefaultTableModel tableTest = new DefaultTableModel(db.tablePrintOfDatabase(), db.getTableColumnNames());
  76.    
  77.    
  78.    
  79.     public SauGUI() throws SQLException {
  80.         initComponents();
  81.        
  82.        
  83.  
  84.     }
  85.  
  86.     /**
  87.      * This method is called from within the constructor to initialize the form.
  88.      * WARNING: Do NOT modify this code. The content of this method is always
  89.      * regenerated by the Form Editor.
  90.      */
  91.     @SuppressWarnings("unchecked")
  92.     // <editor-fold defaultstate="collapsed" desc="Generated Code">
  93.     private void initComponents() {
  94.  
  95.         inputSQL = new javax.swing.JTextField();
  96.         btnUpdateSQL = new javax.swing.JButton();
  97.         outputInput = new javax.swing.JLabel();
  98.         btnTest = new javax.swing.JButton();
  99.         jScrollPane2 = new javax.swing.JScrollPane();
  100.         tableViewer = new javax.swing.JTable();
  101.  
  102.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  103.         setTitle("frame");
  104.         setBackground(new java.awt.Color(51, 102, 255));
  105.  
  106.         inputSQL.addActionListener(new java.awt.event.ActionListener() {
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  108.                 inputSQLActionPerformed(evt);
  109.             }
  110.         });
  111.  
  112.         btnUpdateSQL.setText("Send query");
  113.         btnUpdateSQL.addActionListener(new java.awt.event.ActionListener() {
  114.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  115.                 btnUpdateSQLActionPerformed(evt);
  116.             }
  117.         });
  118.  
  119.         outputInput.setText("jLabel1");
  120.  
  121.         btnTest.setText("jButton1");
  122.         btnTest.addActionListener(new java.awt.event.ActionListener() {
  123.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  124.                 btnTestActionPerformed(evt);
  125.             }
  126.         });
  127.  
  128.         tableViewer.setModel(tableTest
  129.         );
  130.         jScrollPane2.setViewportView(tableViewer);
  131.  
  132.         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
  133.         getContentPane().setLayout(layout);
  134.         layout.setHorizontalGroup(
  135.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  136.             .add(layout.createSequentialGroup()
  137.                 .add(38, 38, 38)
  138.                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  139.                     .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
  140.                         .add(inputSQL)
  141.                         .add(btnUpdateSQL))
  142.                     .add(layout.createSequentialGroup()
  143.                         .add(27, 27, 27)
  144.                         .add(outputInput))
  145.                     .add(btnTest))
  146.                 .add(33, 33, 33)
  147.                 .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  148.                 .addContainerGap(81, Short.MAX_VALUE))
  149.         );
  150.         layout.setVerticalGroup(
  151.             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  152.             .add(layout.createSequentialGroup()
  153.                 .add(36, 36, 36)
  154.                 .add(inputSQL, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
  155.                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
  156.                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
  157.                     .add(layout.createSequentialGroup()
  158.                         .add(btnUpdateSQL)
  159.                         .add(18, 18, 18)
  160.                         .add(outputInput)
  161.                         .add(36, 36, 36)
  162.                         .add(btnTest))
  163.                     .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
  164.                 .addContainerGap(110, Short.MAX_VALUE))
  165.         );
  166.  
  167.         layout.linkSize(new java.awt.Component[] {btnUpdateSQL, inputSQL}, org.jdesktop.layout.GroupLayout.VERTICAL);
  168.  
  169.         pack();
  170.     }// </editor-fold>
  171.  
  172.    
  173.    
  174.    
  175.     private void btnUpdateSQLActionPerformed(java.awt.event.ActionEvent evt) {                                            
  176.         try {
  177.             // TODO add your handling code here:
  178.             db.executeQuery(inputSQL.getText());
  179.             outputInput.setText(Integer.toString(db.getRows()));
  180.            
  181.            
  182.            
  183.            
  184.            
  185.     //        tableViewer.setModel(new javax.swing.table.DefaultTableModel(db.tablePrintOfDatabase(),db.getTableColumnNames()));
  186.          //   db.table();
  187.         } catch (SQLException ex) {
  188.             Logger.getLogger(SauGUI.class.getName()).log(Level.SEVERE, null, ex);
  189.         }
  190.        
  191.     }                                            
  192.  
  193.     private void inputSQLActionPerformed(java.awt.event.ActionEvent evt) {                                        
  194.         // TODO add your handling code here:
  195.     }                                        
  196.  
  197.    
  198.    
  199.    
  200.     //TEST KNAPP
  201.     private void btnTestActionPerformed(java.awt.event.ActionEvent evt) {                                        
  202.         /*
  203.         try {
  204.             // TODO add your handling code here:
  205.         //    db.table();
  206.         //    db.getTableColumnNames();
  207.         } catch (SQLException ex) {
  208.             Logger.getLogger(SauGUI.class.getName()).log(Level.SEVERE, null, ex);
  209.         }
  210.         */
  211.     }                                      
  212.  
  213.     /**
  214.      * @param args the command line arguments
  215.      */
  216.     public static void main(String args[]) {
  217.         /* Set the Nimbus look and feel */
  218.        
  219.        
  220.        
  221.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  222.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  223.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  224.          */
  225.         try {
  226.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  227.                 if ("Nimbus".equals(info.getName())) {
  228.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  229.                     break;
  230.                 }
  231.             }
  232.         } catch (ClassNotFoundException ex) {
  233.             java.util.logging.Logger.getLogger(SauGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  234.         } catch (InstantiationException ex) {
  235.             java.util.logging.Logger.getLogger(SauGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  236.         } catch (IllegalAccessException ex) {
  237.             java.util.logging.Logger.getLogger(SauGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  238.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  239.             java.util.logging.Logger.getLogger(SauGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  240.         }
  241.         //</editor-fold>
  242.  
  243.    
  244.    
  245.        
  246.         /* Create and display the form */
  247.         java.awt.EventQueue.invokeLater(new Runnable() {
  248.             public void run() {
  249.                 try {
  250.                     new SauGUI().setVisible(true);
  251.                 } catch (SQLException ex) {
  252.                     Logger.getLogger(SauGUI.class.getName()).log(Level.SEVERE, null, ex);
  253.                 }
  254.                
  255.                
  256.             }
  257.         });
  258.        
  259.        
  260.        
  261.     }
  262.     // Variables declaration - do not modify
  263.     private javax.swing.JButton btnTest;
  264.     private javax.swing.JButton btnUpdateSQL;
  265.     private javax.swing.JTextField inputSQL;
  266.     private javax.swing.JScrollPane jScrollPane2;
  267.     private javax.swing.JLabel outputInput;
  268.     private javax.swing.JTable tableViewer;
  269.     // End of variables declaration
  270.     private javax.swing.table.DefaultTableModel dfTableModel;
  271.  
  272.    
  273. }
Advertisement
Add Comment
Please, Sign In to add comment