Java tutorial
import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.pdf.PdfWriter; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.sql.ResultSet; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.Timer; import javax.swing.table.DefaultTableModel; import sun.applet.Main; /* * 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. */ /** * * @author Devvara Rishivian */ public class MainFrame extends javax.swing.JFrame { String nol_jam = ""; String nol_menit = ""; String nol_detik = ""; String kasir = ""; String idpangan; String idombe; int regopangan; int regoombe; String makanan; String minuman; /** * Creates new form MainFrame */ public MainFrame() { initComponents(); selectData(); setTanggal(); setJam(); setKasir(); } /** * 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() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); lblJam = new javax.swing.JLabel(); lblTgl = new javax.swing.JLabel(); lblKasir = new javax.swing.JLabel(); jLabel4 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); tabelData = new javax.swing.JTable(); btnPrint = new javax.swing.JButton(); btnSave = new javax.swing.JButton(); btnClear = new javax.swing.JButton(); btnDel = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); tfQtyMa = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); tfIDTransaksi = new javax.swing.JTextField(); tfIDMakanan = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); cbIDMA = new javax.swing.JComboBox<>(); jPanel3 = new javax.swing.JPanel(); jPanel4 = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); lblJam1 = new javax.swing.JLabel(); lblTgl2 = new javax.swing.JLabel(); lblTgl3 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); jTable2 = new javax.swing.JTable(); btnPrint1 = new javax.swing.JButton(); btnSave1 = new javax.swing.JButton(); btnClear1 = new javax.swing.JButton(); btnDel1 = new javax.swing.JButton(); jLabel11 = new javax.swing.JLabel(); tfIDMinuman1 = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); tfIDTransaksi1 = new javax.swing.JTextField(); tfIDMakanan1 = new javax.swing.JTextField(); jLabel14 = new javax.swing.JLabel(); jComboBox2 = new javax.swing.JComboBox<>(); cbIDMI = new javax.swing.JComboBox<>(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); tfIDMinuman = new javax.swing.JTextField(); jLabel17 = new javax.swing.JLabel(); tfQtyMi = new javax.swing.JTextField(); btnProses = new javax.swing.JButton(); jLabel18 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); tfTotal = new javax.swing.JTextField(); lblDisc = new javax.swing.JLabel(); tfBayar = new javax.swing.JTextField(); jLabel21 = new javax.swing.JLabel(); tfKembali = new javax.swing.JTextField(); jLabel22 = new javax.swing.JLabel(); jLabel23 = new javax.swing.JLabel(); btnHitung = new javax.swing.JButton(); btnExit = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(153, 153, 0)); jPanel1.setLayout(null); jPanel2.setBackground(new java.awt.Color(0, 153, 204)); jPanel2.setLayout(null); jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 36)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Warung Sido Mampir"); jPanel2.add(jLabel1); jLabel1.setBounds(30, 10, 390, 48); jLabel3.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel3.setForeground(new java.awt.Color(255, 255, 255)); jLabel3.setText("Jalan Raya Sawojajar no. 69"); jPanel2.add(jLabel3); jLabel3.setBounds(30, 60, 210, 30); lblJam.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblJam.setForeground(new java.awt.Color(255, 255, 255)); lblJam.setText("Jam"); jPanel2.add(lblJam); lblJam.setBounds(1110, 90, 90, 30); lblTgl.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblTgl.setForeground(new java.awt.Color(255, 255, 255)); lblTgl.setText("Tanggal"); jPanel2.add(lblTgl); lblTgl.setBounds(1120, 50, 60, 30); lblKasir.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblKasir.setForeground(new java.awt.Color(255, 255, 255)); lblKasir.setText("Kasir : Devvara"); jPanel2.add(lblKasir); lblKasir.setBounds(1100, 10, 90, 30); jLabel4.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel4.setForeground(new java.awt.Color(255, 255, 255)); jLabel4.setText("082272149463"); jPanel2.add(jLabel4); jLabel4.setBounds(30, 80, 210, 30); jPanel1.add(jPanel2); jPanel2.setBounds(0, 0, 1200, 120); tabelData.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 }, { 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 }, { 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 }, { 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[] { "ID Transaksi", "Nama Makanan", "Nama Minuman", "Qty Makanan", "Qty Minuman", "Harga Makanan", "Harga Minuman", "Total Harga" })); jScrollPane1.setViewportView(tabelData); jPanel1.add(jScrollPane1); jScrollPane1.setBounds(430, 120, 770, 270); btnPrint.setText("PRINT"); btnPrint.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPrintActionPerformed(evt); } }); jPanel1.add(btnPrint); btnPrint.setBounds(930, 470, 160, 50); btnSave.setText("SAVE"); btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt); } }); jPanel1.add(btnSave); btnSave.setBounds(550, 400, 160, 50); btnClear.setText("CLEAR"); btnClear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearActionPerformed(evt); } }); jPanel1.add(btnClear); btnClear.setBounds(740, 400, 160, 50); btnDel.setText("DELETE"); btnDel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDelActionPerformed(evt); } }); jPanel1.add(btnDel); btnDel.setBounds(930, 400, 160, 50); jLabel2.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel2.setForeground(new java.awt.Color(255, 255, 255)); jLabel2.setText("ID Minuman"); jPanel1.add(jLabel2); jLabel2.setBounds(20, 360, 130, 30); jPanel1.add(tfQtyMa); tfQtyMa.setBounds(180, 300, 230, 30); jLabel6.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel6.setForeground(new java.awt.Color(255, 255, 255)); jLabel6.setText("Pilih ID Makanan"); jPanel1.add(jLabel6); jLabel6.setBounds(20, 240, 130, 30); tfIDTransaksi.setText("format id = tgl/bulan/id contoh : 150301"); jPanel1.add(tfIDTransaksi); tfIDTransaksi.setBounds(180, 140, 230, 30); jPanel1.add(tfIDMakanan); tfIDMakanan.setBounds(180, 190, 230, 30); jLabel7.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel7.setForeground(new java.awt.Color(255, 255, 255)); jLabel7.setText("ID Makanan"); jPanel1.add(jLabel7); jLabel7.setBounds(20, 190, 130, 30); cbIDMA.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Lihat ID Makanan", "Mie Goreng", "Mie Rebus", "Gedang Goreng", "Menjes", "Kerupuk", "Jemblem", " " })); cbIDMA.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbIDMAActionPerformed(evt); } }); jPanel1.add(cbIDMA); cbIDMA.setBounds(180, 240, 230, 40); jPanel3.setBackground(new java.awt.Color(102, 102, 0)); jPanel3.setLayout(null); jPanel4.setBackground(new java.awt.Color(102, 0, 0)); jPanel4.setLayout(null); jLabel8.setFont(new java.awt.Font("Segoe UI", 1, 36)); // NOI18N jLabel8.setForeground(new java.awt.Color(255, 255, 255)); jLabel8.setText("Warung Sido Mampir"); jPanel4.add(jLabel8); jLabel8.setBounds(30, 10, 390, 48); jLabel9.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel9.setForeground(new java.awt.Color(255, 255, 255)); jLabel9.setText("Jalan Raya Sawojajar no. 69"); jPanel4.add(jLabel9); jLabel9.setBounds(30, 60, 210, 30); lblJam1.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblJam1.setForeground(new java.awt.Color(255, 255, 255)); lblJam1.setText("Jam"); jPanel4.add(lblJam1); lblJam1.setBounds(1130, 90, 60, 30); lblTgl2.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblTgl2.setForeground(new java.awt.Color(255, 255, 255)); lblTgl2.setText("Tanggal"); jPanel4.add(lblTgl2); lblTgl2.setBounds(1130, 50, 60, 30); lblTgl3.setFont(new java.awt.Font("Segoe UI", 0, 11)); // NOI18N lblTgl3.setForeground(new java.awt.Color(255, 255, 255)); lblTgl3.setText("Kasir : Devvara"); jPanel4.add(lblTgl3); lblTgl3.setBounds(1100, 10, 90, 30); jLabel10.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel10.setForeground(new java.awt.Color(255, 255, 255)); jLabel10.setText("082272149463"); jPanel4.add(jLabel10); jLabel10.setBounds(30, 80, 210, 30); jPanel3.add(jPanel4); jPanel4.setBounds(0, 0, 1200, 120); jTable2.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, 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, 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, null, null, null, null, null, null } }, new String[] { "Nama Makanan", "Nama Minuman", "Qty Makanan", "Qty Minuman", "Harga Makanan", "Harga Minuman", "Total Harga" })); jScrollPane2.setViewportView(jTable2); jPanel3.add(jScrollPane2); jScrollPane2.setBounds(460, 120, 740, 270); btnPrint1.setText("PRINT"); jPanel3.add(btnPrint1); btnPrint1.setBounds(1030, 400, 160, 50); btnSave1.setText("SAVE"); jPanel3.add(btnSave1); btnSave1.setBounds(470, 400, 160, 50); btnClear1.setText("CLEAR"); jPanel3.add(btnClear1); btnClear1.setBounds(660, 400, 160, 50); btnDel1.setText("DELETE"); jPanel3.add(btnDel1); btnDel1.setBounds(850, 400, 160, 50); jLabel11.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel11.setForeground(new java.awt.Color(255, 255, 255)); jLabel11.setText("ID Minuman"); jPanel3.add(jLabel11); jLabel11.setBounds(20, 300, 130, 30); jPanel3.add(tfIDMinuman1); tfIDMinuman1.setBounds(180, 300, 120, 30); jLabel12.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel12.setForeground(new java.awt.Color(255, 255, 255)); jLabel12.setText("ID Transaksi"); jPanel3.add(jLabel12); jLabel12.setBounds(20, 140, 130, 30); jLabel13.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel13.setForeground(new java.awt.Color(255, 255, 255)); jLabel13.setText("Lihat ID Makanan"); jPanel3.add(jLabel13); jLabel13.setBounds(20, 240, 130, 30); jPanel3.add(tfIDTransaksi1); tfIDTransaksi1.setBounds(180, 140, 230, 30); jPanel3.add(tfIDMakanan1); tfIDMakanan1.setBounds(180, 190, 120, 30); jLabel14.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel14.setForeground(new java.awt.Color(255, 255, 255)); jLabel14.setText("ID Makanan"); jPanel3.add(jLabel14); jLabel14.setBounds(20, 190, 130, 30); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Lihat ID Makanan", "Mie Goreng => ID = 001", "Mie Rebus => ID = 002", "Gedang Goreng => ID = 003", "Menjes => ID = 004", "Kerupuk => ID = 005", "Jemblem => ID = 006", " " })); jPanel3.add(jComboBox2); jComboBox2.setBounds(180, 240, 230, 40); jPanel1.add(jPanel3); jPanel3.setBounds(0, 0, 0, 0); cbIDMI.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Lihat ID Minuman", "Kopi Hitam", "Kopi Susu", "Kopi Luwak", "Teh Anget", "Es Teh", "Wedang Jahe", " ", " " })); cbIDMI.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbIDMIActionPerformed(evt); } }); jPanel1.add(cbIDMI); cbIDMI.setBounds(180, 410, 230, 40); jLabel15.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel15.setForeground(new java.awt.Color(255, 255, 255)); jLabel15.setText("Pilih ID Minuman"); jPanel1.add(jLabel15); jLabel15.setBounds(20, 410, 130, 30); jLabel16.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel16.setForeground(new java.awt.Color(255, 255, 255)); jLabel16.setText("Total Item Makanan"); jPanel1.add(jLabel16); jLabel16.setBounds(20, 300, 140, 30); jPanel1.add(tfIDMinuman); tfIDMinuman.setBounds(180, 360, 230, 30); jLabel17.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel17.setForeground(new java.awt.Color(255, 255, 255)); jLabel17.setText("Total Item Minuman"); jPanel1.add(jLabel17); jLabel17.setBounds(20, 470, 140, 30); jPanel1.add(tfQtyMi); tfQtyMi.setBounds(180, 470, 230, 30); btnProses.setText("PROSES TRANSAKSI"); btnProses.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnProsesActionPerformed(evt); } }); jPanel1.add(btnProses); btnProses.setBounds(150, 530, 170, 50); jLabel18.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel18.setForeground(new java.awt.Color(255, 255, 255)); jLabel18.setText("ID Transaksi"); jPanel1.add(jLabel18); jLabel18.setBounds(20, 140, 130, 30); jLabel19.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel19.setForeground(new java.awt.Color(255, 255, 255)); jLabel19.setText("Total"); jPanel1.add(jLabel19); jLabel19.setBounds(460, 470, 130, 30); jPanel1.add(tfTotal); tfTotal.setBounds(550, 470, 160, 30); lblDisc.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N lblDisc.setForeground(new java.awt.Color(255, 255, 255)); lblDisc.setText("Disc"); jPanel1.add(lblDisc); lblDisc.setBounds(770, 470, 40, 30); jPanel1.add(tfBayar); tfBayar.setBounds(550, 510, 160, 30); jLabel21.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel21.setForeground(new java.awt.Color(255, 255, 255)); jLabel21.setText("Kembali"); jPanel1.add(jLabel21); jLabel21.setBounds(460, 550, 130, 30); jPanel1.add(tfKembali); tfKembali.setBounds(550, 550, 160, 30); jLabel22.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel22.setForeground(new java.awt.Color(255, 255, 255)); jLabel22.setText("Bayar"); jPanel1.add(jLabel22); jLabel22.setBounds(460, 510, 130, 30); jLabel23.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N jLabel23.setForeground(new java.awt.Color(255, 255, 255)); jLabel23.setText("Disc %"); jPanel1.add(jLabel23); jLabel23.setBounds(730, 470, 120, 30); btnHitung.setText("Hitung"); btnHitung.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnHitungActionPerformed(evt); } }); jPanel1.add(btnHitung); btnHitung.setBounds(730, 510, 110, 30); btnExit.setText("EXIT"); btnExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExitActionPerformed(evt); } }); jPanel1.add(btnExit); btnExit.setBounds(930, 530, 160, 50); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1200, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)); setSize(new java.awt.Dimension(1216, 639)); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void btnProsesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProsesActionPerformed // TODOd add your handling code here: int tothar; int tunai; int qtyma = Integer.parseInt(tfQtyMa.getText()); int qtymi = Integer.parseInt(tfQtyMi.getText()); //validasi jika id transaksi terisi if (tfIDTransaksi.getText().equals("")) { JOptionPane.showMessageDialog(this, "ID Transaksi Wajib Diisi", "Error", JOptionPane.WARNING_MESSAGE); } else { //validasi id makanan if (tfIDMakanan.getText().equals("MA01")) { makanan = "Mie Goreng"; } else if (tfIDMakanan.getText().equals("MA02")) { makanan = "Mie Rebus"; } else if (tfIDMakanan.getText().equals("MA03")) { makanan = "Gedang Goreng"; } else if (tfIDMakanan.getText().equals("MA04")) { makanan = "Menjes"; } else if (tfIDMakanan.getText().equals("MA05")) { makanan = "Krupuk"; } else if (tfIDMakanan.getText().equals("MA06")) { makanan = "Jemblem"; } else { JOptionPane.showMessageDialog(this, "Makanan tidak ada", "Error", JOptionPane.WARNING_MESSAGE); } //validasi id minuman if (tfIDMinuman.getText().equals("MI01")) { minuman = "Kopi Hitam"; } else if (tfIDMinuman.getText().equals("MI02")) { minuman = "Kopi Susu"; } else if (tfIDMinuman.getText().equals("MI03")) { minuman = "Kopi Luwak"; } else if (tfIDMinuman.getText().equals("MI04")) { minuman = "Teh Anget"; } else if (tfIDMinuman.getText().equals("MI05")) { minuman = "Es Teh"; } else if (tfIDMinuman.getText().equals("MI06")) { minuman = "Wedang Jahe"; } else { JOptionPane.showMessageDialog(this, "Minuman tidak ada", "Error", JOptionPane.WARNING_MESSAGE); } tothar = (regopangan * qtyma) + (regoombe * qtymi); tfTotal.setText(String.valueOf(tothar)); } selectData(); }//GEN-LAST:event_btnProsesActionPerformed private void cbIDMAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbIDMAActionPerformed // TODO add your handling code here: if (cbIDMA.getSelectedItem().equals("Mie Goreng")) { idpangan = "MA01"; regopangan = 6000; tfIDMakanan.setText(idpangan); } else if (cbIDMA.getSelectedItem().equals("Mie Rebus")) { idpangan = "MA02"; regopangan = 6000; tfIDMakanan.setText(idpangan); } else if (cbIDMA.getSelectedItem().equals("Gedang Goreng")) { idpangan = "MA03"; regopangan = 1000; tfIDMakanan.setText(idpangan); } else if (cbIDMA.getSelectedItem().equals("Menjes")) { idpangan = "MA04"; regopangan = 500; tfIDMakanan.setText(idpangan); } else if (cbIDMA.getSelectedItem().equals("Kerupuk")) { idpangan = "MA05"; regopangan = 500; tfIDMakanan.setText(idpangan); } else if (cbIDMA.getSelectedItem().equals("Jemblem")) { idpangan = "MA06"; regopangan = 500; tfIDMakanan.setText(idpangan); } else { JOptionPane.showMessageDialog(this, "ID Makanan tidak ada gan", "Error", JOptionPane.WARNING_MESSAGE); } }//GEN-LAST:event_cbIDMAActionPerformed private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed // TODO add your handling code here: dispose(); }//GEN-LAST:event_btnExitActionPerformed private void cbIDMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbIDMIActionPerformed // TODO add your handling code here: if (cbIDMI.getSelectedItem().equals("Kopi Hitam")) { idombe = "MI01"; regoombe = 3500; tfIDMinuman.setText(idombe); } else if (cbIDMI.getSelectedItem().equals("Kopi Susu")) { idombe = "MI02"; regoombe = 5000; tfIDMinuman.setText(idombe); } else if (cbIDMI.getSelectedItem().equals("Kopi Luwak")) { idombe = "MI03"; regoombe = 60000; tfIDMinuman.setText(idombe); } else if (cbIDMI.getSelectedItem().equals("Teh Anget")) { idombe = "MI04"; regoombe = 2500; tfIDMinuman.setText(idombe); } else if (cbIDMI.getSelectedItem().equals("Es Teh")) { idombe = "MI05"; regoombe = 3000; tfIDMinuman.setText(idombe); } else if (cbIDMI.getSelectedItem().equals("Wedang Jahe")) { idombe = "MI06"; regoombe = 5000; tfIDMinuman.setText(idombe); } else { JOptionPane.showMessageDialog(this, "ID Minuman tidak ada gan", "Error", JOptionPane.WARNING_MESSAGE); } }//GEN-LAST:event_cbIDMIActionPerformed private void btnHitungActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHitungActionPerformed // TODO add your handling code here: double kembali; int tothar = Integer.parseInt(tfTotal.getText()); if (tothar >= 200.000) { lblDisc.setText("5"); kembali = (Integer.parseInt(tfBayar.getText()) - Integer.parseInt(tfTotal.getText())) * 0.5; tfKembali.setText(String.valueOf(kembali)); } else { lblDisc.setText("0"); kembali = Integer.parseInt(tfBayar.getText()) - Integer.parseInt(tfTotal.getText()); tfKembali.setText(String.valueOf(kembali)); } }//GEN-LAST:event_btnHitungActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed // TODO add your handling code here: tfIDTransaksi.setText(""); tfIDMakanan.setText(""); tfQtyMa.setText(""); tfIDMinuman.setText(""); tfQtyMi.setText(""); tfTotal.setText(""); tfBayar.setText(""); tfKembali.setText(""); }//GEN-LAST:event_btnClearActionPerformed private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed // TODO add your handling code here: try { // TODO add your handling code here: String SQL = "Select * From tb_transaksi"; ResultSet rs = KoneksiDB.executeQuery(SQL); Document doc = new Document(); try { PdfWriter.getInstance(doc, new FileOutputStream("Report.pdf")); } catch (DocumentException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.open(); try { doc.add(new Paragraph(" Warung Sido Mampir")); doc.add(new Paragraph( " Kenikmatan Nongki bersama kengkawan")); doc.add(new Paragraph(" ")); doc.add(new Paragraph("Waktu Pembelian : " + lblJam.getText())); doc.add(new Paragraph("Tanggal Pembelian : " + lblTgl.getText())); doc.add(new Paragraph("Nama Kasir : " + lblKasir.getText())); doc.add(new Paragraph("ID Transaksi: ")); try { while (rs.next()) { String id_transaksi = rs.getString(1); doc.add(new Paragraph(" " + id_transaksi)); } } catch (SQLException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.add(new Paragraph(" Total Harga : " + tfTotal.getText())); doc.add(new Paragraph( " Diskon : " + lblDisc.getText())); doc.add(new Paragraph(" Jumlah Bayar : " + tfBayar.getText())); } catch (DocumentException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } doc.close(); } catch (FileNotFoundException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_btnPrintActionPerformed private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed // TODO add your handling code here: int terbayar = Integer.parseInt(tfTotal.getText()); int tothar = Integer.parseInt(tfTotal.getText()); if ("".equals(tfIDTransaksi.getText())) { JOptionPane.showMessageDialog(this, "Harap Lengkapi Data", "ERROR", JOptionPane.WARNING_MESSAGE); } else { String SQL = "INSERT INTO tb_transaksi (id_transaksi,makanan,qty_makanan,minuman,qty_minuman,qty_harga,terbayar) " + "VALUES('" + tfIDTransaksi.getText() + "','" + tfIDMakanan.getText() + "','" + tfQtyMa.getText() + "','" + tfIDMinuman.getText() + "','" + tfQtyMi.getText() + "','" + tothar + "','" + terbayar + "')"; int status = KoneksiDB.execute(SQL); if (status == 1) { JOptionPane.showMessageDialog(this, "Data berhasil Di tambahkan", "Sukses", JOptionPane.INFORMATION_MESSAGE); selectData(); setTanggal(); setJam(); } else { JOptionPane.showMessageDialog(this, "Data gagal Di tambahkan", "Gagal", JOptionPane.WARNING_MESSAGE); } } }//GEN-LAST:event_btnSaveActionPerformed private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDelActionPerformed // TODO add your handling code here: int baris = tabelData.getSelectedRow(); if (baris != -1) { String id = tabelData.getValueAt(baris, 0).toString(); String SQL = "DELETE FROM tb_transaksi WHERE id_transaksi='" + id + "'"; int status = KoneksiDB.execute(SQL); if (status == 1) { JOptionPane.showMessageDialog(this, "Data berhasil dihapus", "Sukses", JOptionPane.INFORMATION_MESSAGE); selectData(); } else { JOptionPane.showMessageDialog(this, "Data gagal dihapus", "Gagal", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(this, "Pilih Baris Data Terlebih Dahulu", "Error", JOptionPane.WARNING_MESSAGE); } }//GEN-LAST:event_btnDelActionPerformed /** * @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(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainFrame.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 MainFrame().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnClear; private javax.swing.JButton btnClear1; private javax.swing.JButton btnDel; private javax.swing.JButton btnDel1; private javax.swing.JButton btnExit; private javax.swing.JButton btnHitung; private javax.swing.JButton btnPrint; private javax.swing.JButton btnPrint1; private javax.swing.JButton btnProses; private javax.swing.JButton btnSave; private javax.swing.JButton btnSave1; private javax.swing.JComboBox<String> cbIDMA; private javax.swing.JComboBox<String> cbIDMI; private javax.swing.JComboBox<String> jComboBox2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; 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.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTable jTable2; private javax.swing.JLabel lblDisc; private javax.swing.JLabel lblJam; private javax.swing.JLabel lblJam1; private javax.swing.JLabel lblKasir; private javax.swing.JLabel lblTgl; private javax.swing.JLabel lblTgl2; private javax.swing.JLabel lblTgl3; private javax.swing.JTable tabelData; private javax.swing.JTextField tfBayar; private javax.swing.JTextField tfIDMakanan; private javax.swing.JTextField tfIDMakanan1; private javax.swing.JTextField tfIDMinuman; private javax.swing.JTextField tfIDMinuman1; private javax.swing.JTextField tfIDTransaksi; private javax.swing.JTextField tfIDTransaksi1; private javax.swing.JTextField tfKembali; private javax.swing.JTextField tfQtyMa; private javax.swing.JTextField tfQtyMi; private javax.swing.JTextField tfTotal; // End of variables declaration//GEN-END:variables private void setTanggal() { java.util.Date skrg = new java.util.Date(); java.text.SimpleDateFormat kal = new SimpleDateFormat("dd/MM/yyyy"); lblTgl.setText(kal.format(skrg)); } private void setJam() { ActionListener taskPerformer = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Date dt = new Date(); int nilai_jam = dt.getHours(); int nilai_menit = dt.getMinutes(); int nilai_detik = dt.getSeconds(); if (nilai_jam <= 9) { nol_jam = "0"; } if (nilai_menit <= 9) { nol_menit = "0"; } if (nilai_detik <= 9) { nol_detik = "0"; } String jam = nol_jam + Integer.toString(nilai_jam); String menit = nol_menit + Integer.toString(nilai_menit); String detik = nol_detik + Integer.toString(nilai_detik); lblJam.setText("Jam " + jam + ":" + menit + ":" + detik); } }; new Timer(100, taskPerformer).start(); } private void selectData() { String kolom[] = { "id_transaksi", "makanan", "qty_makanan", "minuman", "qty_minuman", "qty_harga", "terbayar" }; DefaultTableModel dtm = new DefaultTableModel(null, kolom); String SQL = "SELECT * FROM tb_transaksi"; ResultSet rs = KoneksiDB.executeQuery(SQL); try { while (rs.next()) { String id_transaksi = rs.getString(1); String makanan = rs.getString(2); String qty_makanan = rs.getString(3); String minuman = rs.getString(4); String qty_minuman = rs.getString(5); String qty_harga = rs.getString(6); String terbayar = rs.getString(7); String data[] = { id_transaksi, makanan, qty_makanan, minuman, qty_minuman, qty_harga, terbayar }; dtm.addRow(data); } } catch (SQLException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } tabelData.setModel(dtm); } private void setKasir() { String SQL = "SELECT * FROM tb_akun"; ResultSet result = KoneksiDB.executeQuery(SQL); try { while (result.next()) { String namaKasir = result.getString(1); lblKasir.setText("Kasir = " + namaKasir); } } catch (SQLException ex) { Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); } } }