Rabu, 19 Juli 2017

TUGAS UAS PEMROGRAMAN
1.) Deskripsi Program. 
           
 Program yang saya buat adalah program Pembayaran yang berfungsi untuk menjumlahkan suatu    barang dan menampilkas hasil dari penjumlahan tersebut yang dimana akan tersimpan pada database mysql.



2.) Komponen.

- Button Close <------------MANUAL
- Button Hitung <---------- MANUAL
- Button Save
- Button Refresh
- Button Delete
- Button New



3.) Formula/SourceCode


SourceCode pada Button

3.1.).Button Calculate


3.2.) Button Close



Hasil Run :






Berikut adalah SourceCode keseluruhan

private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
    }                                            

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
        int[] selected = masterTable.getSelectedRows();
        List<project.Kemer_1> toRemove = new ArrayList<project.Kemer_1>(selected.length);
        for (int idx = 0; idx < selected.length; idx++) {
            project.Kemer_1 k = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(k);
            entityManager.remove(k);
        }
        list.removeAll(toRemove);
    }                                           

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
        project.Kemer_1 k = new project.Kemer_1();
        entityManager.persist(k);
        list.add(k);
        int row = list.size() - 1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
    }                                        
   
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
        } catch (RollbackException rex) {
            rex.printStackTrace();
            entityManager.getTransaction().begin();
            List<project.Kemer_1> merged = new ArrayList<project.Kemer_1>(list.size());
            for (project.Kemer_1 k : list) {
                merged.add(entityManager.merge(k));
            }
            list.clear();
            list.addAll(merged);
        }
    }                                         

    private void kodebarangFocusLost(java.awt.event.FocusEvent evt) {                                    
        // TODO add your handling code here:
        if (kodebarang.getText().equals(("001"))){
            namabarang.setText("Roti Keju");
             hargabarang.setText("8000");
        }else if (kodebarang.getText().equals(("002"))){
                  namabarang.setText("Roti Chocolate");
                 hargabarang.setText("10000");
           
       }else if ( kodebarang.getText().equals(("003"))){
                  namabarang.setText("Roti Vanilla");
                  hargabarang.setText("8000");
        }else if (kodebarang.getText().equals(("004"))){
                  namabarang.setText("Roti  Strawberry");
                  hargabarang.setText("8000");
        }else if (kodebarang.getText().equals(("005"))){
                  namabarang.setText("Roti pisang");
                  hargabarang.setText("10000");
                 
        }
    }                                   

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
        int harga=Integer.parseInt(hargabarang.getText());
        int jumlah=Integer.parseInt(jumlahbarang.getText());
       
        int total=(harga*jumlah);
        hargatotal.setText(""+total);
    }                                       

    private void closeActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        System.exit(0);

    }                                    


    // Variables declaration - do not modify                    
    private javax.swing.JButton close;
    private javax.swing.JButton deleteButton;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JLabel hargaBarangLabel;
    private javax.swing.JLabel hargaTotalLabel;
    private javax.swing.JTextField hargabarang;
    private javax.swing.JTextField hargatotal;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jumlahBarangLabel;
    private javax.swing.JTextField jumlahbarang;
    private javax.swing.JLabel kodeBarangLabel;
    private javax.swing.JTextField kodebarang;
    private java.util.List<project.Kemer_1> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JLabel namaBarangLabel;
    private javax.swing.JTextField namabarang;
    private javax.swing.JButton newButton;
    private javax.persistence.Query query;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration                  
    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(NewMasterDetailForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(NewMasterDetailForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(NewMasterDetailForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(NewMasterDetailForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setContentPane(new NewMasterDetailForm());
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
   
}
Read More ->>
Diberdayakan oleh Blogger.