|
| 1 | +/* |
| 2 | + * To change this license header, choose License Headers in Project Properties. |
| 3 | + * To change this template file, choose Tools | Templates |
| 4 | + * and open the template in the editor. |
| 5 | + */ |
| 6 | +package labnerd; |
| 7 | + |
| 8 | +import javax.swing.JOptionPane; |
| 9 | +import javax.swing.table.DefaultTableModel; |
| 10 | + |
| 11 | +/** |
| 12 | + * |
| 13 | + * @author NONT |
| 14 | + */ |
| 15 | +public class Delete extends javax.swing.JFrame { |
| 16 | + |
| 17 | + /** |
| 18 | + * Creates new form Delete |
| 19 | + */ |
| 20 | + Student std = new Student(); |
| 21 | + private Object NameTextField; |
| 22 | + public Delete() { |
| 23 | + initComponents(); |
| 24 | + std.fillStudentJtable(jTable1, ""); //เรียกใช้ตารางข้อมูล |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * This method is called from within the constructor to initialize the form. |
| 29 | + * WARNING: Do NOT modify this code. The content of this method is always |
| 30 | + * regenerated by the Form Editor. |
| 31 | + */ |
| 32 | + @SuppressWarnings("unchecked") |
| 33 | + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents |
| 34 | + private void initComponents() { |
| 35 | + |
| 36 | + jPanel1 = new javax.swing.JPanel(); |
| 37 | + jPanel3 = new javax.swing.JPanel(); |
| 38 | + jLabel9 = new javax.swing.JLabel(); |
| 39 | + jLabelDelete = new javax.swing.JLabel(); |
| 40 | + jScrollPane1 = new javax.swing.JScrollPane(); |
| 41 | + jTable1 = new javax.swing.JTable(); |
| 42 | + jTextField_STD_ID = new javax.swing.JTextField(); |
| 43 | + |
| 44 | + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); |
| 45 | + setLocation(new java.awt.Point(300, 200)); |
| 46 | + setResizable(false); |
| 47 | + setSize(new java.awt.Dimension(1280, 720)); |
| 48 | + |
| 49 | + jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labnerd/exit.png"))); // NOI18N |
| 50 | + jLabel9.addMouseListener(new java.awt.event.MouseAdapter() { |
| 51 | + public void mouseClicked(java.awt.event.MouseEvent evt) { |
| 52 | + jLabel9MouseClicked(evt); |
| 53 | + } |
| 54 | + }); |
| 55 | + |
| 56 | + jLabelDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/labnerd/cancel.png"))); // NOI18N |
| 57 | + jLabelDelete.addMouseListener(new java.awt.event.MouseAdapter() { |
| 58 | + public void mouseClicked(java.awt.event.MouseEvent evt) { |
| 59 | + jLabelDeleteMouseClicked(evt); |
| 60 | + } |
| 61 | + }); |
| 62 | + |
| 63 | + jTable1.setFont(new java.awt.Font("Bangna New", 0, 16)); // NOI18N |
| 64 | + jTable1.setModel(new javax.swing.table.DefaultTableModel( |
| 65 | + new Object [][] { |
| 66 | + |
| 67 | + }, |
| 68 | + new String [] { |
| 69 | + "Student Number", "First Name", "Last Name", "Sex", "Birth Day" |
| 70 | + } |
| 71 | + )); |
| 72 | + jTable1.addMouseListener(new java.awt.event.MouseAdapter() { |
| 73 | + public void mouseClicked(java.awt.event.MouseEvent evt) { |
| 74 | + jTable1MouseClicked(evt); |
| 75 | + } |
| 76 | + }); |
| 77 | + jScrollPane1.setViewportView(jTable1); |
| 78 | + |
| 79 | + jTextField_STD_ID.setEditable(false); |
| 80 | + |
| 81 | + javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); |
| 82 | + jPanel3.setLayout(jPanel3Layout); |
| 83 | + jPanel3Layout.setHorizontalGroup( |
| 84 | + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 85 | + .addGroup(jPanel3Layout.createSequentialGroup() |
| 86 | + .addContainerGap() |
| 87 | + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1268, Short.MAX_VALUE) |
| 88 | + .addContainerGap()) |
| 89 | + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() |
| 90 | + .addGap(19, 19, 19) |
| 91 | + .addComponent(jLabel9) |
| 92 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
| 93 | + .addComponent(jTextField_STD_ID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
| 94 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| 95 | + .addComponent(jLabelDelete) |
| 96 | + .addGap(26, 26, 26)) |
| 97 | + ); |
| 98 | + jPanel3Layout.setVerticalGroup( |
| 99 | + jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 100 | + .addGroup(jPanel3Layout.createSequentialGroup() |
| 101 | + .addContainerGap() |
| 102 | + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 103 | + .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 104 | + .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING) |
| 105 | + .addComponent(jLabelDelete, javax.swing.GroupLayout.Alignment.TRAILING)) |
| 106 | + .addComponent(jTextField_STD_ID, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)) |
| 107 | + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) |
| 108 | + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE) |
| 109 | + .addGap(39, 39, 39)) |
| 110 | + ); |
| 111 | + |
| 112 | + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); |
| 113 | + jPanel1.setLayout(jPanel1Layout); |
| 114 | + jPanel1Layout.setHorizontalGroup( |
| 115 | + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 116 | + .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
| 117 | + ); |
| 118 | + jPanel1Layout.setVerticalGroup( |
| 119 | + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 120 | + .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) |
| 121 | + ); |
| 122 | + |
| 123 | + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); |
| 124 | + getContentPane().setLayout(layout); |
| 125 | + layout.setHorizontalGroup( |
| 126 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 127 | + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
| 128 | + ); |
| 129 | + layout.setVerticalGroup( |
| 130 | + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) |
| 131 | + .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) |
| 132 | + ); |
| 133 | + |
| 134 | + pack(); |
| 135 | + }// </editor-fold>//GEN-END:initComponents |
| 136 | + |
| 137 | + // โชว์ข้อมูล แก้ไขได้ |
| 138 | + private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked |
| 139 | + // TODO add your handling code here: |
| 140 | + int rowIndex = jTable1.getSelectedRow(); |
| 141 | + DefaultTableModel model = (DefaultTableModel)jTable1.getModel(); |
| 142 | + |
| 143 | + jTextField_STD_ID.setText(model.getValueAt(rowIndex,0).toString()); |
| 144 | + |
| 145 | + }//GEN-LAST:event_jTable1MouseClicked |
| 146 | + |
| 147 | + private void jLabelDeleteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabelDeleteMouseClicked |
| 148 | + |
| 149 | + // TODO add your handling code here: |
| 150 | + if(jTextField_STD_ID.getText().equals("")){ |
| 151 | + JOptionPane.showMessageDialog(null, "No Student Selected"); |
| 152 | + } |
| 153 | + else{ |
| 154 | + int id = Integer.valueOf(jTextField_STD_ID.getText()); |
| 155 | + std.insert('d', id, null, null, null, null,null); |
| 156 | + std.fillStudentJtable(jTable1, ""); |
| 157 | + Delete delete = new Delete(); |
| 158 | + delete.setVisible(true); |
| 159 | + System.out.println("Pass"); |
| 160 | + this.setVisible(false); |
| 161 | + |
| 162 | + } |
| 163 | + }//GEN-LAST:event_jLabelDeleteMouseClicked |
| 164 | + |
| 165 | + private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked |
| 166 | + // TODO add your handling code here: |
| 167 | + Main3 main = new Main3(); |
| 168 | + main.setVisible(true); |
| 169 | + System.out.println("Pass"); |
| 170 | + this.setVisible(false); |
| 171 | + }//GEN-LAST:event_jLabel9MouseClicked |
| 172 | + |
| 173 | + /** |
| 174 | + * @param args the command line arguments |
| 175 | + */ |
| 176 | + public static void main(String args[]) { |
| 177 | + /* Set the Nimbus look and feel */ |
| 178 | + //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> |
| 179 | + /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. |
| 180 | + * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html |
| 181 | + */ |
| 182 | + try { |
| 183 | + for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { |
| 184 | + if ("Nimbus".equals(info.getName())) { |
| 185 | + javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
| 186 | + break; |
| 187 | + } |
| 188 | + } |
| 189 | + } catch (ClassNotFoundException ex) { |
| 190 | + java.util.logging.Logger.getLogger(Delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 191 | + } catch (InstantiationException ex) { |
| 192 | + java.util.logging.Logger.getLogger(Delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 193 | + } catch (IllegalAccessException ex) { |
| 194 | + java.util.logging.Logger.getLogger(Delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 195 | + } catch (javax.swing.UnsupportedLookAndFeelException ex) { |
| 196 | + java.util.logging.Logger.getLogger(Delete.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
| 197 | + } |
| 198 | + //</editor-fold> |
| 199 | + |
| 200 | + /* Create and display the form */ |
| 201 | + java.awt.EventQueue.invokeLater(new Runnable() { |
| 202 | + public void run() { |
| 203 | + new Delete().setVisible(true); |
| 204 | + } |
| 205 | + }); |
| 206 | + } |
| 207 | + |
| 208 | + // Variables declaration - do not modify//GEN-BEGIN:variables |
| 209 | + private javax.swing.JLabel jLabel9; |
| 210 | + private javax.swing.JLabel jLabelDelete; |
| 211 | + private javax.swing.JPanel jPanel1; |
| 212 | + private javax.swing.JPanel jPanel3; |
| 213 | + private javax.swing.JScrollPane jScrollPane1; |
| 214 | + private javax.swing.JTable jTable1; |
| 215 | + private javax.swing.JTextField jTextField_STD_ID; |
| 216 | + // End of variables declaration//GEN-END:variables |
| 217 | +} |
0 commit comments