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 com.tech.auju.display; import com.tech.auju.implementation.GudangImpl; import com.tech.auju.objects.Pembelian; import com.tech.auju.util.DocumentMaker; import java.io.FileNotFoundException; import java.sql.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; import net.sf.jasperreports.engine.JRException; import org.joda.time.DateTime; /** * * @author sora */ public class Gudang extends javax.swing.JFrame { private final int PEMBELIAN = 0; private final int RETUR = 1; private final int APPROVED = 2; private GudangImpl gudangImpl; private Pembelian pembelian; /** * Creates new form Gudang */ public Gudang() { initComponents(); gudangImpl = new GudangImpl(); tblBaru.setModel(gudangImpl.getTableModel(PEMBELIAN)); gudangImpl.fillTable(tblBaru); gudangImpl.initReturTable(); tblRetur.setModel(gudangImpl.getTableModel(RETUR)); gudangImpl.updateReturTable(tblRetur); } /** * 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">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); pnlBaru = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); tblBaru = new javax.swing.JTable(); jLabel2 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); txtDetail = new javax.swing.JTextArea(); pnlApproved = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jScrollPane4 = new javax.swing.JScrollPane(); tblApproved = new javax.swing.JTable(); pnlRetur = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); tblRetur = new javax.swing.JTable(); btnSubmit = new javax.swing.JButton(); btnRetur = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); btnSetujui = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Gudang v.2.0"); jLabel1.setText("Daftar pembelian"); tblBaru.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 } }, new String[] { "Nama Bahan", "Jumlah", "Harga", "Tanggal", "Supplier" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class }; boolean[] canEdit = new boolean[] { false, false, false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); tblBaru.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tblBaruMouseClicked(evt); } }); jScrollPane1.setViewportView(tblBaru); jLabel2.setText("Detail"); txtDetail.setEditable(false); txtDetail.setColumns(20); txtDetail.setRows(5); jScrollPane2.setViewportView(txtDetail); javax.swing.GroupLayout pnlBaruLayout = new javax.swing.GroupLayout(pnlBaru); pnlBaru.setLayout(pnlBaruLayout); pnlBaruLayout.setHorizontalGroup(pnlBaruLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlBaruLayout.createSequentialGroup().addContainerGap() .addGroup(pnlBaruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE) .addGroup(pnlBaruLayout.createSequentialGroup() .addGroup(pnlBaruLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1).addComponent(jLabel2)) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane2)) .addContainerGap())); pnlBaruLayout.setVerticalGroup(pnlBaruLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlBaruLayout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE))); jTabbedPane1.addTab( "<html><body leftmargin=0 topmargin=8 marginwidth=35 marginheight=5>Bahan Baru</body></html>", pnlBaru); jLabel4.setText("Daftar bahan yang disetujui"); tblApproved.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 } }, new String[] { "Nama", "Jumlah", "Harga", "Tanggal", "Supplier" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane4.setViewportView(tblApproved); javax.swing.GroupLayout pnlApprovedLayout = new javax.swing.GroupLayout(pnlApproved); pnlApproved.setLayout(pnlApprovedLayout); pnlApprovedLayout.setHorizontalGroup(pnlApprovedLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlApprovedLayout.createSequentialGroup().addContainerGap() .addGroup(pnlApprovedLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlApprovedLayout.createSequentialGroup().addComponent(jLabel4).addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)) .addContainerGap())); pnlApprovedLayout.setVerticalGroup(pnlApprovedLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlApprovedLayout.createSequentialGroup().addContainerGap().addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE) .addContainerGap())); jTabbedPane1.addTab( "<html><body leftmargin=0 topmargin=8 marginwidth=35 marginheight=5>Bahan Telah disetujui</body></html>", pnlApproved); jLabel3.setText("Daftar retur"); tblRetur.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 } }, new String[] { "Nama", "Jumlah", "Harga", "Tanggal", "Supplier" }) { boolean[] canEdit = new boolean[] { false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane3.setViewportView(tblRetur); javax.swing.GroupLayout pnlReturLayout = new javax.swing.GroupLayout(pnlRetur); pnlRetur.setLayout(pnlReturLayout); pnlReturLayout.setHorizontalGroup(pnlReturLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlReturLayout.createSequentialGroup().addContainerGap() .addGroup(pnlReturLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlReturLayout.createSequentialGroup().addComponent(jLabel3).addGap(0, 0, Short.MAX_VALUE)) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 591, Short.MAX_VALUE)) .addContainerGap())); pnlReturLayout.setVerticalGroup(pnlReturLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlReturLayout.createSequentialGroup().addContainerGap().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 344, Short.MAX_VALUE) .addContainerGap())); jTabbedPane1.addTab( "<html><body leftmargin=0 topmargin=8 marginwidth=35 marginheight=5>Bahan Retur</body></html>", pnlRetur); btnSubmit.setText("Submit"); btnSubmit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSubmitActionPerformed(evt); } }); btnRetur.setText("Tambah ke retur"); btnRetur.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnReturActionPerformed(evt); } }); jButton1.setText("Log out"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); btnSetujui.setText("Setujui"); btnSetujui.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSetujuiActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap().addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnSetujui) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(btnRetur) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(btnSubmit) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addComponent(jTabbedPane1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnSubmit).addComponent(btnRetur).addComponent(jButton1) .addComponent(btnSetujui)) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void tblBaruMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBaruMouseClicked // TODO add your handling code here: tableRecordListener(); }//GEN-LAST:event_tblBaruMouseClicked private void btnReturActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReturActionPerformed // TODO add your handling code here: if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Are you sure to return this product?", "Attention", JOptionPane.YES_NO_OPTION)) { gudangImpl.returnPembelian(tblBaru.getSelectedRow()); gudangImpl.remove(tblBaru.getSelectedRow()); tblRetur.setModel(gudangImpl.getTableModel(RETUR)); gudangImpl.updateReturTable(tblRetur); tblBaru.setModel(gudangImpl.getTableModel(PEMBELIAN)); gudangImpl.updatePembelianTable(tblBaru); } }//GEN-LAST:event_btnReturActionPerformed private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitActionPerformed // TODO add your handling code here: gudangImpl.submitData(); generate(); //REPORTS should be here JOptionPane.showMessageDialog(this, "Data was submited succesfully.", "Attention", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_btnSubmitActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: this.dispose(); new Login(this, true).setVisible(true); }//GEN-LAST:event_jButton1ActionPerformed private void btnSetujuiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetujuiActionPerformed // TODO add your handling code here: if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(this, "Are you sure if this material is available ?", "Attention", JOptionPane.YES_NO_OPTION)) { gudangImpl.addToPembeliansApproved(tblBaru.getSelectedRow()); gudangImpl.remove(tblBaru.getSelectedRow()); tblBaru.setModel(gudangImpl.getTableModel(PEMBELIAN)); tblApproved.setModel(gudangImpl.getTableModel(APPROVED)); gudangImpl.updatePembelianTable(tblBaru); gudangImpl.updateApprovedTable(tblApproved); } }//GEN-LAST:event_btnSetujuiActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Gudang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Gudang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Gudang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Gudang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Gudang().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnRetur; private javax.swing.JButton btnSetujui; private javax.swing.JButton btnSubmit; private javax.swing.JButton jButton1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JPanel pnlApproved; private javax.swing.JPanel pnlBaru; private javax.swing.JPanel pnlRetur; private javax.swing.JTable tblApproved; private javax.swing.JTable tblBaru; private javax.swing.JTable tblRetur; private javax.swing.JTextArea txtDetail; // End of variables declaration//GEN-END:variables /** * Fill txtDetail with information of Bahan. */ private void tableRecordListener() { this.pembelian = gudangImpl.getPembelian(tblBaru.getSelectedRow()); String text = "Nama bahan : " + pembelian.getBahan().getNama_bahan() + "\nJumlah : " + pembelian.getBahan().getJumlah_bahan() + "\nHarga satuan : " + pembelian.getBahan().getHarga_satuan() + "\nMerk : " + pembelian.getBahan().getMerk().getNama_merk() + "\nWarna : " + pembelian.getBahan().getWarna().getNama_warna() + "\nJenis : " + pembelian.getBahan().getJenis().getNama_jenis() + "\nSupplier : " + pembelian.getBahan().getSupplier().getNama_supplier() + "\nAlamat supplier : " + pembelian.getBahan().getSupplier().getAlamat_supplier(); txtDetail.setText(text); } private void generate() { // int d1 = (int) spDay1.getValue(); // int d2 = (int) spDay2.getValue(); // int m1 = cbMonth1.getSelectedIndex() + 1; // int m2 = cbMonth2.getSelectedIndex() + 1; // //1900 // int y1 = (int) spYear1.getValue(); // int y2 = (int) spYear2.getValue(); DateTime dt = new DateTime(); int y = dt.getYear() - 1900; int m = dt.monthOfYear().get() - 1; int d = dt.dayOfMonth().get(); Date date1 = new Date(y, m, d); Date date2 = new Date(y, m, d); try { new DocumentMaker().printArsip(date1, date2); } catch (FileNotFoundException ex) { Logger.getLogger(DocGenerator.class.getName()).log(Level.SEVERE, null, ex); } catch (JRException ex) { Logger.getLogger(DocGenerator.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("1. " + date1.getDay() + date1.getMonth() + date1.getYear()); // System.out.println("2. " + d2 + m2 + y2); } }