haloooo...... semuanya.
hehehehehea
dh lama juga nih gk ngeposting aye. Jadi kangen.
Baiklah,,kita langsunga aja yah.
Kali ini saya akan memposting rogram Insert data ke tabel. Tapi untuk ini data yang kita input ke tabel tidak tersimpan seutuhnya karna aku gk menggunakan database. Artinya apabila program nya sudah kita keluarkan berarti data yang tadinya kita input akan hilang.
Untuk itu mari kita mulai programnya..
Kali ini saya akan memposting rogram Insert data ke tabel. Tapi untuk ini data yang kita input ke tabel tidak tersimpan seutuhnya karna aku gk menggunakan database. Artinya apabila program nya sudah kita keluarkan berarti data yang tadinya kita input akan hilang.
Untuk itu mari kita mulai programnya..
Gambar : Design Form |
Gambae : Hasil |
Source Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * FormDataKaryawan.java * * Created on 06 Apr 12, 14:51:08 */ package formdatakaryawan; import java.util.ArrayList; import javax.swing.table.DefaultTableModel; /** * * @author Toshiba */ public class FormDataKaryawan extends javax.swing.JFrame { DefaultTableModel modelTabelDataKaryawan = new DefaultTableModel(); public FormDataKaryawan() { initComponents(); modelTabelDataKaryawan.addColumn("Nama Karyawan"); modelTabelDataKaryawan.addColumn("NIK"); modelTabelDataKaryawan.addColumn("Jabatan/Posisi"); modelTabelDataKaryawan.addColumn("Umur"); modelTabelDataKaryawan.addColumn("Alamat"); modelTabelDataKaryawan.addColumn("No. HP/Tlpn"); modelTabelDataKaryawan.addColumn("Tunjangan Perbulan"); modelTabelDataKaryawan.addColumn("Gaji"); tabelDataKaryawan.setModel(modelTabelDataKaryawan); } /** 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() { jLabel1 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); textNama = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); textUmur = new javax.swing.JTextField(); textNIK = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); textAlamat = new javax.swing.JTextField(); textNoHP = new javax.swing.JTextField(); textTunjangan = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); textJabatan = new javax.swing.JTextField(); textGaji = new javax.swing.JTextField(); jPanel2 = new javax.swing.JPanel(); buttonInsert = new javax.swing.JButton(); buttonLoad = new javax.swing.JButton(); buttonUpdate = new javax.swing.JButton(); buttonClear = new javax.swing.JButton(); buttonDelete = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); tabelDataKaryawan = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("DATA KARYAWAN"); setBackground(new java.awt.Color(153, 204, 255)); setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); setFont(new java.awt.Font("Bradley Hand ITC", 1, 24)); setForeground(new java.awt.Color(102, 204, 255)); jLabel1.setFont(new java.awt.Font("NSimSun", 1, 25)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("DATA KARYAWAN PT LUM JADI Tbk"); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Data Karyawan :", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 18))); // NOI18N jLabel5.setText("Umur"); jLabel8.setText("Tunjangan Perbulan"); jLabel3.setText("NIK"); jLabel4.setText("Jabatan/Posisi"); jLabel2.setText("Nama Karyawan"); jLabel7.setText("No. HP.Tlpn"); jLabel6.setText("Alamat"); jLabel9.setText("Gaji"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(jLabel4) .addComponent(jLabel5) .addComponent(jLabel6) .addComponent(jLabel7) .addComponent(jLabel8) .addComponent(jLabel9)) .addGap(26, 26, 26) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(textUmur) .addComponent(textJabatan, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(textGaji) .addComponent(textTunjangan) .addComponent(textNoHP) .addComponent(textAlamat) .addComponent(textNama, javax.swing.GroupLayout.DEFAULT_SIZE, 231, Short.MAX_VALUE) .addComponent(textNIK)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(textNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(textNIK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(textJabatan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(textUmur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(textAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(textNoHP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8) .addComponent(textTunjangan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9) .addComponent(textGaji, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Proses :", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 18))); // NOI18N buttonInsert.setText("INSERT"); buttonInsert.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); buttonInsert.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonInsertActionPerformed(evt); } }); buttonLoad.setText("LOAD"); buttonLoad.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); buttonLoad.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonLoadActionPerformed(evt); } }); buttonUpdate.setText("UPDATE"); buttonUpdate.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); buttonUpdate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonUpdateActionPerformed(evt); } }); buttonClear.setText("CLEAR"); buttonClear.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); buttonClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonClearActionPerformed(evt); } }); buttonDelete.setText("DELETE"); buttonDelete.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED)); buttonDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonDeleteActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(buttonClear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(buttonInsert, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(buttonLoad, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(buttonDelete, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE) .addComponent(buttonUpdate, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(buttonInsert, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(buttonUpdate, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE) .addComponent(buttonLoad, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(buttonDelete, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE) .addComponent(buttonClear, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)) .addContainerGap()) ); tabelDataKaryawan.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null}, {null, null, null, null, null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7", "Title 8" } )); jScrollPane1.setViewportView(tabelDataKaryawan); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup() .addGap(195, 195, 195) .addComponent(jLabel1)) .addGroup(layout.createSequentialGroup() .addGap(30, 30, 30) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(105, 105, 105) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1))) .addContainerGap(34, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addGap(18, 18, 18) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void buttonInsertActionPerformed(java.awt.event.ActionEvent evt) { ArrayList<Object> objekKaryawan = new ArrayList<Object>(); objekKaryawan.add(textNama.getText()); objekKaryawan.add(textNIK.getText()); objekKaryawan.add(textJabatan.getText()); objekKaryawan.add(textUmur.getText()); objekKaryawan.add(textAlamat.getText()); objekKaryawan.add(textNoHP.getText()); objekKaryawan.add(textTunjangan.getText()); objekKaryawan.add(textGaji.getText()); modelTabelDataKaryawan.addRow(objekKaryawan.toArray()); } private void buttonLoadActionPerformed(java.awt.event.ActionEvent evt) { int i = tabelDataKaryawan.getSelectedRow(); textNama.setText(tabelDataKaryawan.getValueAt(i, 0).toString()); textNIK.setText(tabelDataKaryawan.getValueAt(i, 1).toString()); textJabatan.setText(tabelDataKaryawan.getValueAt(i, 2).toString()); textUmur.setText(tabelDataKaryawan.getValueAt(i, 3).toString()); textAlamat.setText(tabelDataKaryawan.getValueAt(i, 4).toString()); textNoHP.setText(tabelDataKaryawan.getValueAt(i, 5).toString()); textTunjangan.setText(tabelDataKaryawan.getValueAt(i, 6).toString()); textGaji.setText(tabelDataKaryawan.getValueAt(i, 7).toString()); } private void buttonUpdateActionPerformed(java.awt.event.ActionEvent evt) { int i = tabelDataKaryawan.getSelectedRow(); modelTabelDataKaryawan.setValueAt(textNama.getText(), i, 0); modelTabelDataKaryawan.setValueAt(textNIK.getText(), i, 1); modelTabelDataKaryawan.setValueAt(textJabatan.getText(), i, 2); modelTabelDataKaryawan.setValueAt(textUmur.getText(), i, 3); modelTabelDataKaryawan.setValueAt(textAlamat.getText(), i, 4); modelTabelDataKaryawan.setValueAt(textNoHP.getText(), i, 5); modelTabelDataKaryawan.setValueAt(textTunjangan.getText(), i, 6); modelTabelDataKaryawan.setValueAt(textGaji.getText(), i, 7); } private void buttonClearActionPerformed(java.awt.event.ActionEvent evt) { textNama.setText(""); textNIK.setText(""); textJabatan.setText(""); textUmur.setText(""); textAlamat.setText(""); textNoHP.setText(""); textTunjangan.setText(""); textGaji.setText(""); } private void buttonDeleteActionPerformed(java.awt.event.ActionEvent evt) { int i = tabelDataKaryawan.getSelectedRow(); modelTabelDataKaryawan.fireTableRowsDeleted(i, ERROR); modelTabelDataKaryawan.getDataVector().removeElementAt(i); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new FormDataKaryawan().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton buttonClear; private javax.swing.JButton buttonDelete; private javax.swing.JButton buttonInsert; private javax.swing.JButton buttonLoad; private javax.swing.JButton buttonUpdate; 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.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable tabelDataKaryawan; private javax.swing.JTextField textAlamat; private javax.swing.JTextField textGaji; private javax.swing.JTextField textJabatan; private javax.swing.JTextField textNIK; private javax.swing.JTextField textNama; private javax.swing.JTextField textNoHP; private javax.swing.JTextField textTunjangan; private javax.swing.JTextField textUmur; // End of variables declaration } |
Tidak ada komentar:
Posting Komentar