Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package MstrKasKeluar; import Class.DbKoneksi; import Class.MstrKasKeluar; import java.awt.Dimension; import java.awt.Toolkit; import java.sql.Connection; import java.text.SimpleDateFormat; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.JOptionPane; import org.apache.commons.lang.StringUtils; /** * * @author Suhendar */ public class Entry extends javax.swing.JFrame { Connection _Cnn; DbKoneksi getCnn = new DbKoneksi(); private Dimension dimensi = Toolkit.getDefaultToolkit().getScreenSize(); String _ID; // untuk primarykey String _Status; // save atau delete String _kas; public Entry(String kas, String id, String status) { initComponents(); _ID = id; if (status.equals("edit")) { btn_simpan.setText("Update"); } _Status = status; _kas = kas; Search(); this.setLocation(dimensi.width / 2 - this.getWidth() / 2, dimensi.height / 2 - this.getHeight() / 2); } private void Search() { try { MstrKasKeluar x = new MstrKasKeluar(); x.Search(_ID); if (x._Akses.equals("-")) { txt_id.setText(x.id); String tgl = StringUtils.substringBeforeLast(x.tgl, " "); txt_tgl_keluar.setDate(java.sql.Date.valueOf(tgl)); txt_ket.setText(x.ket); txt_jum.setText(x.jum_uang); txt_id.setEditable(false); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jXTitledPanel1 = new org.jdesktop.swingx.JXTitledPanel(); txt_id = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); txt_tgl_keluar = new org.jdesktop.swingx.JXDatePicker(); txt_jum = new javax.swing.JFormattedTextField(); jScrollPane1 = new javax.swing.JScrollPane(); txt_ket = new javax.swing.JEditorPane(); jPanel3 = new javax.swing.JPanel(); btn_simpan = new javax.swing.JButton(); btn_batal = new javax.swing.JButton(); btn_keluar = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(53, 73, 178)); jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N jLabel6.setForeground(new java.awt.Color(255, 255, 255)); jLabel6.setText("Entry Data"); 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().addComponent(jLabel6) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel6).addContainerGap())); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 0, Short.MAX_VALUE)); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE)); jXTitledPanel1.setTitle("+ Manipulasi Kas Keluar"); jLabel5.setText("Jumlah Uang Rp."); jLabel4.setText("Keterangan"); jLabel2.setText("Tgl Masuk"); jLabel1.setText("Id "); txt_jum.setText("-"); txt_jum.setToolTipText("-"); // NOI18N txt_jum.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N txt_jum.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txt_jumActionPerformed(evt); } }); jScrollPane1.setViewportView(txt_ket); javax.swing.GroupLayout jXTitledPanel1Layout = new javax.swing.GroupLayout( jXTitledPanel1.getContentContainer()); jXTitledPanel1.getContentContainer().setLayout(jXTitledPanel1Layout); jXTitledPanel1Layout.setHorizontalGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jXTitledPanel1Layout.createSequentialGroup().addContainerGap().addGroup( jXTitledPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(27, 27, 27) .addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jXTitledPanel1Layout.createSequentialGroup() .addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jXTitledPanel1Layout.createSequentialGroup().addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txt_jum, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txt_tgl_keluar, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(54, 198, Short.MAX_VALUE))))); jXTitledPanel1Layout.setVerticalGroup( jXTitledPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, jXTitledPanel1Layout.createSequentialGroup().addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jXTitledPanel1Layout.createSequentialGroup().addGap(9, 9, 9) .addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(txt_id, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel2).addComponent(txt_tgl_keluar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel4)) .addGroup(jXTitledPanel1Layout.createSequentialGroup().addGap(63, 63, 63) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(5, 5, 5) .addGroup(jXTitledPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5).addComponent(txt_jum, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addContainerGap(23, Short.MAX_VALUE))); btn_simpan.setText("Simpan"); btn_simpan.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_simpanActionPerformed(evt); } }); btn_batal.setText("Batal"); btn_batal.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_batalActionPerformed(evt); } }); btn_keluar.setText("Keluar"); btn_keluar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btn_keluarActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout .setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btn_simpan) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btn_batal, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btn_keluar).addContainerGap())); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btn_simpan).addComponent(btn_batal).addComponent(btn_keluar)) .addContainerGap())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jXTitledPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(0, 0, 0).addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jXTitledPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); pack(); }// </editor-fold>//GEN-END:initComponents private void btn_simpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_simpanActionPerformed try { MstrKasKeluar x = new MstrKasKeluar(); x.Search(txt_id.getText()); x.id = txt_id.getText(); SimpleDateFormat t = new SimpleDateFormat("yyyy-MM-dd"); String _tgl = t.format(txt_tgl_keluar.getDate()); x.tgl = _tgl; x.ket = txt_ket.getText(); x.jum_uang = txt_jum.getText(); if (x._Akses.equals("-")) { x.UpdateData(); x.UpdateData2(); txt_id.setEditable(false); JOptionPane.showMessageDialog(null, "Data Berhasil diubah"); } else { x.SaveData(); x.SaveData2(); txt_id.setEditable(false); JOptionPane.showMessageDialog(null, "Data Berhasil disimpan"); } } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex); } }//GEN-LAST:event_btn_simpanActionPerformed private void btn_batalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_batalActionPerformed // TODO add your handling code here: }//GEN-LAST:event_btn_batalActionPerformed private void btn_keluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_keluarActionPerformed dispose(); }//GEN-LAST:event_btn_keluarActionPerformed private void txt_jumActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_jumActionPerformed }//GEN-LAST:event_txt_jumActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btn_batal; public javax.swing.JButton btn_keluar; public javax.swing.JButton btn_simpan; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private org.jdesktop.swingx.JXTitledPanel jXTitledPanel1; public javax.swing.JTextField txt_id; private javax.swing.JFormattedTextField txt_jum; private javax.swing.JEditorPane txt_ket; private org.jdesktop.swingx.JXDatePicker txt_tgl_keluar; // End of variables declaration//GEN-END:variables }