Sabtu, 16 Januari 2010

MEMBUAT FORM KURSUS MENGGUNAKAN NETBEANS

import java.sql.*;
import javax.swing.JOptionPane;


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* kursus.java
*
* Created on Jan 9, 2010, 7:49:28 AM
*/

/**
*
* @author Budiman bin Suher
*/
public class kursus extends javax.swing.JFrame {

/** Creates new form kursus */
int biayaDaftar,biayaKursus,biayaUjian,totalBiaya,sisa;
String ket_BiayaDaftar, ket_BiayaKursus, ket_BiayaUjian;
static Statement stetmen = null;

public kursus() {
initComponents();
}

/** 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")
// //GEN-BEGIN:initComponents
private void initComponents() {

bgjkel = new javax.swing.ButtonGroup();
buttonGroup2 = new javax.swing.ButtonGroup();
buttonGroup3 = new javax.swing.ButtonGroup();
buttonGroup4 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jtxNomorDaftar = new javax.swing.JTextField();
jcbTanggal = new javax.swing.JComboBox();
jcbBulan = new javax.swing.JComboBox();
jtxTahun = new javax.swing.JTextField();
jtxAlamat = new javax.swing.JTextField();
jtxNama = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jcbKodeKursus = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
jtxNamaKursus = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jtxLamaKursus = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jtfBiayaDaftar = new javax.swing.JTextField();
jcbBiayaDaftar = new javax.swing.JCheckBox();
jLabel10 = new javax.swing.JLabel();
jtfBiayaKursus = new javax.swing.JTextField();
jcbBiayaKursus = new javax.swing.JCheckBox();
jLabel11 = new javax.swing.JLabel();
jcbBiayaUjian = new javax.swing.JCheckBox();
jtfBiayaUjian = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
jtfTotalBiaya = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jtfSisa = new javax.swing.JTextField();
jbSimpan = new javax.swing.JButton();
jbBatal = new javax.swing.JButton();
jbRubah = new javax.swing.JButton();
jbHapus = new javax.swing.JButton();
jbCari = new javax.swing.JButton();
jbKeluar = new javax.swing.JButton();
jbPrivate = new javax.swing.JRadioButton();
jbReguler = new javax.swing.JRadioButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Nomor Pendaftaran");

jLabel2.setText("Tanggal Pendaftaran");

jLabel3.setText("Nama");

jLabel4.setText("Alamat");

jcbTanggal.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tanggal", "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" }));
jcbTanggal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcbTanggalActionPerformed(evt);
}
});

jcbBulan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bulan", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" }));

jtxNama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jtxNamaActionPerformed(evt);
}
});

jLabel5.setText("Kode Kursus");

jcbKodeKursus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KOM", "BHI", "AKT" }));
jcbKodeKursus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcbKodeKursusActionPerformed(evt);
}
});

jLabel6.setText("Nama Kursus");

jLabel7.setText("Lama Kursus");

jLabel8.setText("Jenis Kursus");

jLabel9.setText("Biaya Pendaftaran");

jcbBiayaDaftar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcbBiayaDaftarActionPerformed(evt);
}
});

jLabel10.setText("Biaya Kursus");

jcbBiayaKursus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcbBiayaKursusActionPerformed(evt);
}
});

jLabel11.setText("Biaya Ujian");

jcbBiayaUjian.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jcbBiayaUjianActionPerformed(evt);
}
});

jLabel12.setText("Total Biaya");

jLabel13.setText("Sisa");

jbSimpan.setText("Simpan");
jbSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbSimpanActionPerformed(evt);
}
});

jbBatal.setText("Batal");
jbBatal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbBatalActionPerformed(evt);
}
});

jbRubah.setText("Rubah");
jbRubah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbRubahActionPerformed(evt);
}
});

jbHapus.setText("Hapus");
jbHapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbHapusActionPerformed(evt);
}
});

jbCari.setText("Cari");
jbCari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbCariActionPerformed(evt);
}
});

jbKeluar.setText("Keluar");
jbKeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbKeluarActionPerformed(evt);
}
});

jbPrivate.setText("Private");
jbPrivate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbPrivateActionPerformed(evt);
}
});

jbReguler.setText("Reguler");
jbReguler.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbRegulerActionPerformed(evt);
}
});

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)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jtxNomorDaftar, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jcbTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jcbBulan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jtxTahun, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(18, 18, 18)
.addComponent(jcbKodeKursus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel12)
.addComponent(jLabel13))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jtfSisa)
.addComponent(jtfTotalBiaya, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 230, Short.MAX_VALUE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jtxLamaKursus)
.addComponent(jtxNamaKursus, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel8)
.addGap(18, 18, 18)
.addComponent(jbPrivate)
.addGap(18, 18, 18)
.addComponent(jbReguler)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel3))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jtxNama, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jtxAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel10)
.addComponent(jLabel11))
.addGap(118, 118, 118)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jtfBiayaUjian, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
.addComponent(jtfBiayaDaftar, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
.addComponent(jtfBiayaKursus, javax.swing.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jcbBiayaUjian)
.addComponent(jcbBiayaKursus))
.addComponent(jcbBiayaDaftar, javax.swing.GroupLayout.Alignment.TRAILING)))))
.addGroup(layout.createSequentialGroup()
.addComponent(jbSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbBatal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbRubah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jbHapus)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jbCari, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jbKeluar)))
.addGap(72, 72, 72))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(jtxNomorDaftar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jcbBulan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(jcbTanggal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jtxTahun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(jtxNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jtxAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(jcbKodeKursus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(jtxNamaKursus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(jtxLamaKursus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(jbPrivate)
.addComponent(jbReguler))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
.addComponent(jtfBiayaDaftar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jcbBiayaDaftar))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel10)
.addComponent(jtfBiayaKursus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11)
.addComponent(jtfBiayaUjian, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel12)
.addComponent(jtfTotalBiaya, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel13)
.addComponent(jtfSisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(jcbBiayaKursus)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jcbBiayaUjian)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jbSimpan)
.addComponent(jbBatal)
.addComponent(jbRubah)
.addComponent(jbHapus)
.addComponent(jbCari)
.addComponent(jbKeluar)))
);

pack();
}//
//GEN-END:initComponents

private void jbSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbSimpanActionPerformed
// TODO add your handling code here
try
{
String JenisKursus = (jbPrivate.isSelected() ? "Private" : "Reguler");
String perintah = "insert into bismillah values (" +
"'" + jtxNomorDaftar.getText() + "'," +
"'" + jcbTanggal.getSelectedItem()+ "'," +
"'" + jcbBulan.getSelectedItem()+ "'," +
"'" + jtxTahun.getText() + "'," +
"'" + jtxNama.getText() + "'," +
"'" + jtxAlamat.getText() + "'," +
"'" + jcbKodeKursus.getSelectedItem()+ "'," +
"'" + jtxNamaKursus.getText() + "'," +
"'" + jtxLamaKursus.getText() + "'," +
"'" + JenisKursus + "'," +
"'" + jtfBiayaDaftar.getText() + "'," +
"'" + ket_BiayaDaftar + "'," +
"'" + jtfBiayaKursus.getText() + "'," +
"'" + ket_BiayaKursus + "'," +
"'" + jtfBiayaUjian.getText() + "'," +
"'" + ket_BiayaUjian + "'," +
"'" + jtfTotalBiaya.getText() + "'," +
"'" + jtfSisa.getText() + "'" +
")";
int jumlahInsert = stetmen.executeUpdate(perintah);

jcbTanggal.setSelectedIndex(0);
jcbBulan.setSelectedIndex(0);
jcbKodeKursus.setSelectedIndex(0);
jtxAlamat.setText("");
jtfBiayaDaftar.setText("");
jtfBiayaKursus.setText("");
jtfBiayaUjian.setText("");
jtxNamaKursus.setText("");
jtxLamaKursus.setText("");
jtxNama.setText("");
jtxNomorDaftar.setText("");
jtxTahun.setText("");
jtfSisa.setText("");
jtfTotalBiaya.setText("");
jbPrivate.setSelected(false);
jbReguler.setSelected(false);
jcbBiayaDaftar.setSelected(false);
jcbBiayaKursus.setSelected(false);
jcbBiayaUjian.setSelected(false);
JOptionPane.showMessageDialog(null, "Pendaftaran Berhasil","DAFTAR",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(),"PERINGATAN",JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jbSimpanActionPerformed

private void jcbBiayaDaftarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbBiayaDaftarActionPerformed
// TODO add your handling code here:
if(jcbBiayaDaftar.isSelected()==true)
{
biayaDaftar=Integer.parseInt(jtfBiayaDaftar.getText());
ket_BiayaDaftar = "Pembayaran sudah selesai";
}
else
{
biayaDaftar=0;
ket_BiayaDaftar = "Pembayaran belum dilakukan";
}
totalBiaya = 0;
sisa = 0;
totalBiaya = Integer.parseInt(jtfBiayaDaftar.getText()) + Integer.parseInt(jtfBiayaKursus.getText()) + Integer.parseInt(jtfBiayaUjian.getText());
sisa = totalBiaya - biayaDaftar - biayaKursus - biayaUjian;
jtfTotalBiaya.setText(""+totalBiaya);
jtfSisa.setText(""+sisa);


}//GEN-LAST:event_jcbBiayaDaftarActionPerformed

private void jcbTanggalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbTanggalActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jcbTanggalActionPerformed

private void jtxNamaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxNamaActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jtxNamaActionPerformed

private void jcbKodeKursusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbKodeKursusActionPerformed
// TODO add your handling code here:
if(jcbKodeKursus.getSelectedItem()=="KOM")
{
jtxNamaKursus.setText("KOMPUTER");
jtxLamaKursus.setText("1 BULAN");
}
else if(jcbKodeKursus.getSelectedItem()=="BHI")
{
jtxNamaKursus.setText("BAHASA INGGRIS");
jtxLamaKursus.setText("3 BULAN");
}
else if(jcbKodeKursus.getSelectedItem()=="AKT")
{
jtxNamaKursus.setText("AKUTANSI");
jtxLamaKursus.setText("2 BULAN");
}

}//GEN-LAST:event_jcbKodeKursusActionPerformed

private void jbPrivateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPrivateActionPerformed
// TODO add your handling code here:
if(jbPrivate.isSelected()==true)
{
jbReguler.setSelected(false);
if(jcbKodeKursus.getSelectedItem()=="KOM")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("1500000");
jtfBiayaUjian.setText("50000");
}
else if(jcbKodeKursus.getSelectedItem()=="BHI")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("750000");
jtfBiayaUjian.setText("30000");
}
else if(jcbKodeKursus.getSelectedItem()=="AKT")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("800000");
jtfBiayaUjian.setText("40000");
}
else
{
JOptionPane.showMessageDialog(null, "Pilih Jenis Kursus","WARNING",JOptionPane.WARNING_MESSAGE);
jbPrivate.setSelected(false);
}
}

}//GEN-LAST:event_jbPrivateActionPerformed

private void jcbBiayaUjianActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbBiayaUjianActionPerformed
// TODO add your handling code here:
if(jcbBiayaUjian.isSelected()==true)
{
biayaUjian=Integer.parseInt(jtfBiayaUjian.getText());
ket_BiayaUjian = "Sudah Dibayar";
}
else
{
biayaUjian=0;
ket_BiayaUjian = "Belum Dibayar";
}
totalBiaya = 0;
sisa = 0;
totalBiaya = Integer.parseInt(jtfBiayaDaftar.getText()) + Integer.parseInt(jtfBiayaKursus.getText()) + Integer.parseInt(jtfBiayaUjian.getText());
sisa = totalBiaya - biayaDaftar - biayaKursus - biayaUjian;
jtfTotalBiaya.setText(""+totalBiaya);
jtfSisa.setText(""+sisa);


}//GEN-LAST:event_jcbBiayaUjianActionPerformed

private void jbRegulerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRegulerActionPerformed
// TODO add your handling code here:
if(jbReguler.isSelected()==true)
{
jbPrivate.setSelected(false);
if(jcbKodeKursus.getSelectedItem()=="KOM")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("1000000");
jtfBiayaUjian.setText("50000");
}
else if(jcbKodeKursus.getSelectedItem()=="BHI")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("500000");
jtfBiayaUjian.setText("30000");
}
else if(jcbKodeKursus.getSelectedItem()=="AKT")
{
jtfBiayaDaftar.setText("20000");
jtfBiayaKursus.setText("600000");
jtfBiayaUjian.setText("40000");
}
else
{
JOptionPane.showMessageDialog(null, "Pilih Jenis Kursus","WARNING",JOptionPane.WARNING_MESSAGE);
jbReguler.setSelected(false);
}
} // TODO add your handling code here:
}//GEN-LAST:event_jbRegulerActionPerformed

private void jcbBiayaKursusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbBiayaKursusActionPerformed
// TODO add your handling code here:
if(jcbBiayaKursus.isSelected()==true)
{
biayaKursus=Integer.parseInt(jtfBiayaKursus.getText());
ket_BiayaKursus = "Sudah Dibayar";
}
else
{
biayaKursus=0;
ket_BiayaKursus = "Belum Dibayar";
}
totalBiaya = 0;
sisa = 0;
totalBiaya = Integer.parseInt(jtfBiayaDaftar.getText()) + Integer.parseInt(jtfBiayaKursus.getText()) + Integer.parseInt(jtfBiayaUjian.getText());
sisa = totalBiaya - biayaDaftar - biayaKursus - biayaUjian;
jtfTotalBiaya.setText(""+totalBiaya);
jtfSisa.setText(""+sisa);
}//GEN-LAST:event_jcbBiayaKursusActionPerformed

private void jbBatalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBatalActionPerformed
// TODO add your handling code here:
jcbTanggal.setSelectedIndex(0);
jcbBulan.setSelectedIndex(0);
jcbKodeKursus.setSelectedIndex(0);
jtxAlamat.setText("");
jtfBiayaDaftar.setText("");
jtfBiayaKursus.setText("");
jtfBiayaUjian.setText("");
jtxNamaKursus.setText("");
jtxLamaKursus.setText("");
jtxNama.setText("");
jtxNomorDaftar.setText("");
jtxTahun.setText("");
jtfSisa.setText("");
jtfTotalBiaya.setText("");
jbPrivate.setSelected(false);
jbReguler.setSelected(false);
jcbBiayaDaftar.setSelected(false);
jcbBiayaKursus.setSelected(false);
jcbBiayaUjian.setSelected(false);
}//GEN-LAST:event_jbBatalActionPerformed

private void jbRubahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRubahActionPerformed
// TODO add your handling code here:
try
{
String JenisKursus = (jbPrivate.isSelected() ? "Privat" : "Regular");
String perintah = "update bismillah set " +
"NomorDaftar = '" + jtxNomorDaftar.getText() + "'," +
"Tanggal = '" + jcbTanggal.getSelectedItem()+ "'," +
"Bulan = '" + jcbBulan.getSelectedItem()+ "'," +
"Tahun = '" + jtxTahun.getText() + "'," +
"Nama = '" + jtxNama.getText() + "'," +
"Alamat = '" + jtxAlamat.getText() + "'," +
"KodeKursus = '" + jcbKodeKursus.getSelectedItem()+ "'," +
"NamaKursus = '" + jtxNamaKursus.getText() + "'," +
"LamaKursus = '" + jtxLamaKursus.getText() + "'," +
"JenisKursus = '" + JenisKursus + "'," +
"BiayaDaftar = '" + jtfBiayaDaftar.getText() + "'," +
"ket_BiayaDaftat = '" + ket_BiayaDaftar + "'," +
"BiayaKursus = '" + jtfBiayaKursus.getText() + "'," +
"ket_BIayaKursus = '" + ket_BiayaKursus + "'," +
"BiayaUjian = '" + jtfBiayaUjian.getText() + "'," +
"ket_BiayaUjian = '" + ket_BiayaUjian + "'," +
"TotalBiaya = '" + jtfTotalBiaya.getText() + "'," +
"Sisa = '" + jtfSisa.getText() + "'" +
"where NomorDaftar = '" + jtxNomorDaftar.getText() + "'";
int jumlahTerinsert = stetmen.executeUpdate(perintah);
jcbTanggal.setSelectedIndex(0);
jcbBulan.setSelectedIndex(0);
jcbKodeKursus.setSelectedIndex(0);
jtxAlamat.setText("");
jtfBiayaDaftar.setText("");
jtfBiayaKursus.setText("");
jtfBiayaUjian.setText("");
jtxNamaKursus.setText("");
jtxLamaKursus.setText("");
jtxNama.setText("");
jtxNomorDaftar.setText("");
jtxTahun.setText("");
jtfSisa.setText("");
jtfTotalBiaya.setText("");
jbPrivate.setSelected(false);
jbReguler.setSelected(false);
jcbBiayaDaftar.setSelected(false);
jcbBiayaKursus.setSelected(false);
jcbBiayaUjian.setSelected(false);
JOptionPane.showMessageDialog(null, "Perubahan Diterima","EDIT DATA",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(),"PERINGATAN",JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jbRubahActionPerformed

private void jbCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCariActionPerformed
// TODO add your handling code here:
try
{
String perintah = "SELECT * FROM bismillah WHERE NomorDaftar = '" + jtxNomorDaftar.getText() + "'";
ResultSet hasil = stetmen.executeQuery(perintah);

while(hasil.next())
{
jcbTanggal.setSelectedItem(hasil.getString("Tanggal"));
jcbBulan.setSelectedItem(hasil.getString("Bulan"));
jcbKodeKursus.setSelectedItem(hasil.getString("KodeKursus"));
jtxAlamat.setText(hasil.getString("Alamat"));
jtfBiayaDaftar.setText(hasil.getString("BiayaDaftar"));
jtfBiayaKursus.setText(hasil.getString("BiayaKursus"));
jtfBiayaUjian.setText(hasil.getString("BiayaUjian"));
jtxNamaKursus.setText(hasil.getString("NamaKursus"));
jtxLamaKursus.setText(hasil.getString("LamaKursus"));
jtxNama.setText(hasil.getString("Nama"));
jtxTahun.setText(hasil.getString("Tahun"));
jtfSisa.setText(hasil.getString("Sisa"));
jtfTotalBiaya.setText(hasil.getString("TotalBiaya"));
if(hasil.getString("JenisKursus").compareTo("Privat")==0)
{
jbPrivate.setSelected(true);
}
else
{
jbReguler.setSelected(true);
}

if(hasil.getString("ket_BiayaDaftat").compareTo("Sudah Dibayar")==0)
{
jcbBiayaDaftar.setSelected(true);
biayaDaftar = Integer.parseInt(jtfBiayaDaftar.getText());
}
else
{
jcbBiayaDaftar.setSelected(false);
biayaDaftar = 0;
}

if(hasil.getString("ket_BIayaKursus").compareTo("Sudah Dibayar")==0)
{
jcbBiayaKursus.setSelected(true);
biayaKursus = Integer.parseInt(jtfBiayaKursus.getText());
}
else
{
jcbBiayaKursus.setSelected(false);
biayaKursus = 0;
}

if(hasil.getString("ket_BiayaUjian").compareTo("Sudah Dibayar")==0)
{
jcbBiayaUjian.setSelected(true);
biayaUjian = Integer.parseInt(jtfBiayaUjian.getText());
}
else
{
jcbBiayaUjian.setSelected(false);
biayaUjian = 0;
}




}
}

catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(),"PERINGATAN",JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jbCariActionPerformed

private void jbKeluarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbKeluarActionPerformed
// TODO add your handling code here:
System.exit(0);
}//GEN-LAST:event_jbKeluarActionPerformed

private void jbHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbHapusActionPerformed
// TODO add your handling code here:
try
{
String perintah = "DELETE FROM bismillah WHERE NomorDaftar = '" + jtxNomorDaftar.getText() + "'";
int jumlahterdelete = stetmen.executeUpdate(perintah);
jcbTanggal.setSelectedIndex(0);
jcbBulan.setSelectedIndex(0);
jcbKodeKursus.setSelectedIndex(0);
jtxAlamat.setText("");
jtfBiayaDaftar.setText("");
jtfBiayaKursus.setText("");
jtfBiayaUjian.setText("");
jtxNamaKursus.setText("");
jtxLamaKursus.setText("");
jtxNama.setText("");
jtxNomorDaftar.setText("");
jtxTahun.setText("");
jtfSisa.setText("");
jtfTotalBiaya.setText("");
jbPrivate.setSelected(false);
jbReguler.setSelected(false);
jcbBiayaDaftar.setSelected(false);
jcbBiayaKursus.setSelected(false);
jcbBiayaUjian.setSelected(false);
JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus","DELETE",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage(),"PERINGATAN",JOptionPane.WARNING_MESSAGE);
}

}//GEN-LAST:event_jbHapusActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {

try{
Class.forName("com.mysql.jdbc.Driver");
try{
String url = "jdbc:mysql://localhost:3306/DBAstagfirullah";
String user = "root";
String password = "";
Connection koneksi = DriverManager.getConnection(url, user, password);
stetmen = koneksi.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
JOptionPane.showMessageDialog(null, "Koneksi Berhasil","Cek Bebi Cek",JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException ex){
System.out.println("Koneksi gagal ?");
System.out.println("SQLException: " + ex.getMessage());
}
} catch (Exception se){
System.out.println("Driver MySQL tidak ditemukan : " + se);
}

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new kursus().setVisible(true);
}
});
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup bgjkel;
private javax.swing.ButtonGroup buttonGroup2;
private javax.swing.ButtonGroup buttonGroup3;
private javax.swing.ButtonGroup buttonGroup4;
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 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.JButton jbBatal;
private javax.swing.JButton jbCari;
private javax.swing.JButton jbHapus;
private javax.swing.JButton jbKeluar;
private javax.swing.JRadioButton jbPrivate;
private javax.swing.JRadioButton jbReguler;
private javax.swing.JButton jbRubah;
private javax.swing.JButton jbSimpan;
private javax.swing.JCheckBox jcbBiayaDaftar;
private javax.swing.JCheckBox jcbBiayaKursus;
private javax.swing.JCheckBox jcbBiayaUjian;
private javax.swing.JComboBox jcbBulan;
private javax.swing.JComboBox jcbKodeKursus;
private javax.swing.JComboBox jcbTanggal;
private javax.swing.JTextField jtfBiayaDaftar;
private javax.swing.JTextField jtfBiayaKursus;
private javax.swing.JTextField jtfBiayaUjian;
private javax.swing.JTextField jtfSisa;
private javax.swing.JTextField jtfTotalBiaya;
private javax.swing.JTextField jtxAlamat;
private javax.swing.JTextField jtxLamaKursus;
private javax.swing.JTextField jtxNama;
private javax.swing.JTextField jtxNamaKursus;
private javax.swing.JTextField jtxNomorDaftar;
private javax.swing.JTextField jtxTahun;
// End of variables declaration//GEN-END:variables

}


Buat databasenya menggunakan PHP MyAdmin agar lebih memudahkan..
Selamat mencoba!

Tidak ada komentar:

Posting Komentar