Riky Metall's Blog di Facebook!

Like Page halaman rikymetalist.blogspot.com di Facebook!
Dan Update status kamu via rikymetalist.blogspot.com disini!

INFO

- Mohon dibaca : Cara download di Blog ini. (rikymetall's Blog)
- Mohon dibaca : CARA DOWNLOAD via TUSFILES.NET
- Jika terdapat Link Download yang rusak, silahkan laporkan kepada saya melalui
email saya di : rikymetal10@gmail.com

Jasa Pemasangan Iklan

Jasa Pemasangan Iklan

PERHATIAN

Perhatian. Khusus Untuk Daerah MEDAN dan SEKITARNYA. Bagi Anda Mahasiswa/Mahasiswi yang sedang menyelesaikan SKRIPSI ataupun Tugas Akhir tetapi Anda Merasa Bingung, Tidak Sempat dan banyak kesibukan untuk mengerjakannya, Anda bisa Hubungi di

rikymetal10@gmail.com

(Jasa Pengerjaan Skripsi). Hanya Menangani Skripsi Mahasiswa dengan Jurusan sbb :

- Bahasa Indonesia - PBSI
- PKn
- Matematika
- Kimia
- Biologi
- Sejarah

TIDAK MELAYANI Jurusan : Bahasa Inggris, Telekomunikasi, Manajemen dan Teknik Informatika, Komputer.
Untuk Harga Bisa Di Negosiasi kepada Bpk. Sarwono. Alamat silahkan tanya melalui EMAIL yang tercantum di atas.
Namun yang terpenting Anda juga harus Membantu walaupun sedikit agar Anda paham apa isi Skripsi Anda.
Beberapa mahasiswa/i dari kampus terkenal di Medan telah menyelesaikan skripsinya disini. :)

Jika Ada pertanyaan, silahkan kirim pesan Anda di : rikymetal10@gmail.com

Wednesday, April 4, 2012

Aplikasi JAVA Sederhana Menggunakan NetBeans


Konsep NetBeans
NetBeans Sebagai IDE ditujukan untuk memudahkan pemrogramanjava. Dalam NetBeans, pemrograman dilakukan berbasis visual dan even driven, persis seperti IDE lain, misal Borland Delphi dan Microsoft Visual Studio.
Untuk membuat user interface, kita tidak perlu menggunakan teks program secara manual baris perbaris, tapi cukup klik pada komponen palette, teks program akan dihasilkan secara otomatis.
Tampilan Awal IDE Net Beans

Keterangan:
1 .Jendela utama
2.Palette dan properties
3 .Output/debugger console
4.Project explorer
5 .Navigator

Membuat Sebuah Project
Untuk membuat sebuah project baru, pilih New Project pada menu File. Kemudian kita pilih Java pada kolom Categories dan Java Application pada kolom Projects.

Kemudian akan muncullah tampilan awal seperti dibawah ini:



Untuk menampilkan form editor pada palette dan semua komponen GUI, kita harus menambahkan sebuah file bertipe GUI. Caranya adlah pilih New File pada menu File

Akan muncul jendela dialog seperti diatas, maka coba kita pilih Swing GUI Forms pada kolom Categories, dan JFrame Form pada kolom File Types lalu tekan tombol next.
Maka akan muncul sebuah JFrame pada form editor dan palette pada sisi kanan.


Mambuat program sederhana tanpa database
Coba kita buat tampilan seperti contoh gambar diatas menggunakan komponen­komponen yang ada pada palette.
Pada tab Source ada bagian yang tidak dapat diubah souce code nya, bagian tersebut adalah code yang berhubungan dengan GUI yang otomatis di-generate oleh netbeans, dan akan terus berubah seiring perkembangan program yang kita buat, terutama mengenai tampilan.
Bagian tersebut diberi background berbeda oleh netbeans, sehingga kita bisa membedakannya.
Source Code:
/*
* dataMhs.java
*
* Created on February 9, 2008, 9:28 AM */
package workshop;

import javax. swing. JOptionPane;
/* * *
* @author Administrator
*/
public class dataMhs extends javax.swing.JFrame {
/** Creates new form dataMhs */ public dataMhs() {
initComponents();
grpJenkel.add(rdLaki);
grpJenkel.add(rdPerempuan);
//tanggal Lahir
for(int i=1 ;i<=3 1 ;i++) {
if(i<1 0)cmbTgl.addItem("0"+Integer.toString(i)); else cmbTgl.addItem(Integer.toString(i)); }
//bulan lahir
/*for(int i=1 ;i<=12;i++){
if(i<1 0)cmbBln.addItem("0"+Integer.toString(i)); else cmbBln.addItem(Integer.toString(i)); } */
//tahun lahir
for(int i=1970;i<=201 5;i++){
cmbThn.addItem(Integer.toString(i)); }
//bulan Lahir
//for(int i=1 ;i<=12;i++)
}
//Bagian yang tidak dapat di-edit
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code"> private void initComponents() {

j Spinner1 = new javax.swing.JSpinner(); grpJenkel = new javax.swing.ButtonGroup(); lblTest = new javax.swing.JLabel(); lblNim = new javax. swing. JLabel(); txtNim = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); txtNama = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); rdLaki = new javax.swing.JRadioButton(); rdPerempuan = new javax.swing.JRadioButton();
jLabel3 = new javax.swing.JLabel();
j ScrollPane1 = new javax. swing.JScrollPane();
txtAlamat = new javax. swing. JTextArea(); jLabel4 = new javax.swing.JLabel(); txtTempat = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); cmbBln = new javax.swing.JComboBox(); cmbTgl = new javax.swing.JComboBox(); cmbThn = new javax.swing.JComboBox(); btnTampil = new javax.swing.JButton();
setDefaultCloseOperation( j avax . swing. WindowConstants. EXIT_ON_CLO SE); setLocationByPlatform(true);
lblTest. setBackground(new java.awt.Color(204, 204, 0));
lblTest. setFont(new java.awt.Font("Monotype Corsiva", 1, 24)); lblTest. setForeground(new java.awt.Color(255, 0, 51));
lblTest.setText("Data Mahasiswa");
lblTest. setHorizontalTextPosition(javax.swing. SwingConstants.CENTER);
lblNim.setText("NIM");
j Label1.setText("Nama");
j Label2.setText("Jenis Kelamin");
rdLaki.setText("Laki-Laki"); rdLaki.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); rdLaki.setMargin(new java.awt.Insets(0, 0, 0, 0));
rdPerempuan.setText("Perempuan"); rdPerempuan.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); rdPerempuan.setMargin(new java.awt.Insets(0, 0, 0, 0));
jLabel3 .setText("Alamat");

txtAlamat.setColumns(20);
txtAlamat.setRows(5);
j ScrollPane1.setViewportView(txtAlamat);
j Label4.setText("Tempat Lahir"); j Label5 .setText("Tanggal Lahir");
cmbBln.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" }));
btnTampil.setForeground(new java.awt.Color(0, 0, 255)); btnTampil.setText("Tampilkan");
btnTampil.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTampilActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.j desktop.layout. GroupLayout(getContentPane()); getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout. createParallelGroup(org.j desktop.layout. GroupLayout. LEADING) .add(layout.createSequentialGroup()
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout. LEADING)
.add(layout.createSequentialGroup()
.add(116, 116, 116)
.add(lblTest, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 222,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE))
.add(layout.createSequentialGroup() .add(50, 50, 50)
.add(layout.createParallelGroup (org.j desktop . layout. GroupLayout. LEADING) .add(lblNim)
.add(jLabel1) .add(jLabel2) .add(jLabel3) .add(jLabel4) .add(jLabel5))
.add(34, 34, 34)
.add(layout.createParallelGroup (org.j desktop . layout. GroupLayout. LEADING) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 253, Short.MAX_VALUE)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(layout.createSequentialGroup()
.add(rdLaki)
.add(28, 28, 28)
.add(rdPerempuan))
.add(txtNama, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
.add(txtNim, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 150, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(txtTempat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 168, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(org.j desktop.layout. GroupLayout. TRAILING,
layout. createSequentialGroup()
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(btnTampil)
.add(layout.createSequentialGroup()
.add(cmbTgl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 51,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.addPreferredGap(org.j desktop . layout. LayoutStyle .UNRELATED) .add(cmbBln,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.addPreferredGap(org.j desktop . layout. LayoutStyle .UNRELATED)
.add(cmbThn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)))
.add(36, 36, 36)))))
.add(22, 22, 22))
);
layout.setVerticalGroup(
layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(layout.createSequentialGroup()
.addContainerGap()
.add(lblTest)
.addPreferredGap(org.j desktop . layout. LayoutStyle. UNRELATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout.BASELINE) .add(lblNim)
.add(txtNim, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_S IZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE))

.addPreferredGap(org.j desktop.layout. LayoutStyle. UNRELATED)
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout.BASELINE) .add(j Label 1)
.add(txtNama, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop.layout. GroupLayout. PREFERRED_SIZE))
.addPreferredGap(org.j desktop.layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout.BASELINE) .add(j Label2)
.add(rdPerempuan)
.add(rdLaki))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RE LATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(j Label3)
.add(j ScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
59, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout.BASELINE) .add(txtTempat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.add(j Label4))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(layout.createSequentialGroup()
.add(layout.createParallelGroup (org.j desktop . layout. GroupLayout.BASELINE)
.add(cmbTgl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.add(cmbBln, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.add(cmbThn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop . layout. GroupLayout. PREFERRED_SIZE))
.add(18, 18, 18)
.add(btnTampil))
.add(jLabel5))
.addContainerGap(2 1, Short.MAX_VALUE)) );
pack();
} // </editor-fold>
String jenkel, tgl_lahir;
private void btnTampilActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
if(rdLaki.isSelected()) { jenkel="Laki-Laki"; }
if(rdPerempuan.isSelected()) {
jenkel="Perempuan"; }
tgl_lahir=cmbTgl.getSelectedItem()+" -"
+cmbBln.getSelectedItem()+" -"
+cmbThn.getSelectedItem();
JOptionPane.showMessageDialog(null, txtNim.getText() +"\n"+txtNama.getText()
+"\n"+jenkel
+"\n"+txtAlamat.getText()
+"\n"+txtTempat.getText()
Text Box: }+"\n"+tgl_lahir, "Data Mahasiswa",JOptionPane.PLAIN_MESSAGE);
/**
* @param args the command line arguments
*/
public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new dataMhs().setVisible(true);
// Variables declaration - do not modify private javax.swing.JButton btnTampil; private javax.swing.JComboBox cmbBln; private javax.swing.JComboBox cmbTgl; private javax.swing.JComboBox cmbThn; private javax.swing.ButtonGroup grpJenkel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5;
private javax.swing.JScrollPane j ScrollPane1;
private javax.swing.JSpinner j Spinner1; private javax.swing.JLabel lblNim; private javax.swing.JLabel lblTest; private javax.swing.JRadioButton rdLaki; private javax.swing.JRadioButton rdPerempuan;

Text Box: }private javax.swing.JTextArea txtAlamat; private javax.swing.JTextField txtNama; private javax.swing.JTextField txtNim; private javax.swing.JTextField txtTempat; // End of variables declaration

Program sederhana menggunakan database
Berikut adalah contoh aplikasi sederhana seperti program sebelumnya, tetapi menggunakan database sebagai penyimpan data.
Source Code:
/*
* DataMahasiswa.java
*
* Created on February 8, 2008, 11:22 PM
*/
package workshop;
//import com.ibm.oti.connection.btgoep.Connection; //import com.mysql.jdbc. Statement;
import java.sql.*;
import javax. swing. *;

/* * *
* @author boedyst
*/
public class DataMahasiswa extends javax.swing.JFrame {
/** Creates new form DataMahasiswa */ public DataMahasiswa() {
initComponents();
setLocation(250, 100);
grpJenkel.add(rdLaki);
grpJenkel.add(rdPerempuan);
//tanggal Lahir
for(int i=1 ;i<=3 1 ;i++) {
if(i<1 0)cmbTgl.addItem("0"+Integer.toString(i));
else cmbTgl.addItem(Integer.toString(i));
}
//bulan lahir
for(int i=1;i<=12;i++){
if(i<1 0)cmbBln.addItem("0"+Integer.toString(i));
else cmbBln.addItem(Integer.toString(i));
}
//tahun lahir
for(int i=1985;i<=2015;i++)
{cmbThn.addItem(Integer.toString(i)); }
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code"> private void initComponents() {
grpJenkel = new javax.swing.ButtonGroup(); j Label1 = new javax.swing.JLabel(); txtNim = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txtNama = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel();

txtTempat = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); rdLaki = new javax.swing.JRadioButton(); rdPerempuan = new javax.swing.JRadioButton();
jLabel6 = new javax.swing.JLabel(); cmbTgl = new javax.swing.JComboBox(); jLabel7 = new javax.swing.JLabel(); txtAlamat = new javax.swing.JScrollPane(); txtAlmt = new javax.swing.JTextArea(); cmbBln = new javax.swing.JComboBox(); cmbThn = new javax.swing.JComboBox(); jPanel1 = new javax.swing.JPanel(); btnExit = new javax.swing.JButton(); btnEdit = new javax.swing.JButton(); btnSave = new javax.swing.JButton(); btnTampil = new javax.swing.JButton(); btnDelete = new javax.swing.JButton(); btnFind = new javax.swing.JButton();
setDefaultCloseOperation( j avax.swing. WindowConstants. EXIT_ON_CLO SE); setTitle("Data Mahasiswa");
setName("dataMhs"); // NOI18N
setResizable(false);
j Label1.setFont(new java.awt.Font("Papyrus", 0, 12)); jLabel1.setText("NIM");
txtNim.setFont(new java.awt.Font("Papyrus", 0, 12)); txtNim.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNimActionPerformed(evt);
}
});
j Label2.setFont(new java.awt.Font("Papyrus", 1, 12));
j Label2.setHorizontalAlignment(javax.swing. SwingConstants.CENTER); jLabel2.setText("BIODATA MAHASISWA");
j Label3 .setFont(new java.awt.Font("Papyrus", 0, 12)); jLabel3 .setText("Nama");
txtNama.setFont(new java.awt.Font("Papyrus", 0, 12));
j Label5 .setFont(new java.awt.Font("Papyrus", 0, 12)); j Label5 .setText("Tempat Lahir");

txtTempat.setFont(new java.awt.Font("Papyrus", 0, 12));
j Label4.setFont(new java.awt.Font("Papyrus", 0, 12)); j Label4.setText("Jenis Kelamin");
rdLaki.setFont(new java.awt.Font("Papyrus", 0, 12));
rdLaki.setText("Laki-Laki"); rdLaki.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); rdLaki.setMargin(new java.awt.Insets(0, 0, 0, 0));
rdPerempuan.setFont(new java.awt.Font("Papyrus", 0, 12)); rdPerempuan.setText("Perempuan"); rdPerempuan.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); rdPerempuan.setMargin(new java.awt.Insets(0, 0, 0, 0));
j Label6.setFont(new java.awt.Font("Papyrus", 0, 12)); j Label6.setText("Tanggal Lahir");
cmbTgl.setFont(new java.awt.Font("Papyrus", 0, 12));
j Label7.setFont(new java.awt.Font("Papyrus", 0, 12)); j Label7.setText("Alamat");
txtAlmt.setColumns(20);
txtAlmt.setFont(new java.awt.Font("Papyrus", 0, 12)); txtAlmt.setRows(5);
txtAlamat.setViewportView(txtAlmt);
cmbBln.setFont(new java.awt.Font("Papyrus", 0, 12)); cmbThn.setFont(new java.awt.Font("Papyrus", 0, 12));
jPanel1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 0)));
btnExit.setFont(new java.awt.Font("Papyrus", 0, 12));
btnExit.setText("Exit");
btnExit.setAlignmentX(200.0F);
btnExit.setAlignmentY(1 00.0F);
btnExit.addActionListener(new j ava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnExitActionPerformed(evt);
}
});
btnEdit.setFont(new java.awt.Font("Papyrus", 0, 12));

btnEdit.setText("Edit");
btnEdit.addActionListener(new j ava.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEditActionPerformed(evt);
}
});
btnSave.setFont(new java.awt.Font("Papyrus", 0, 12));
btnSave.setText(" Save");
btnSave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnSaveActionPerformed(evt);
}
});
btnTampil.setFont(new java.awt.Font("Papyrus", 0, 12)); btnTampil.setText("Tampil");
btnTampil.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnTampilActionPerformed(evt);
}
});
btnDelete.setFont(new java.awt.Font("Papyrus", 0, 12)); btnDelete.setText("Delete");
btnDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDeleteActionPerformed(evt);
}
});
btnFind.setFont(new java.awt.Font("Papyrus", 0, 12));
btnFind.setText("Find");
btnFind.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnFindActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout jPanel 1 Layout = new
org.j desktop . layout. GroupLayout( jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout. setHorizontalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(j Panel 1 Layout. createSequentialGroup()
.add(29, 29, 29)

.add(jPanel1Layout. createParallelGroup (org.j desktop.layout.GroupLayout.LEADING, false)
.add(j Panel 1 Layout. create SequentialGroup()
.add(btnDelete) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnFind, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(j Panel 1 Layout. create SequentialGroup()
.add(btnTampil) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(btnSave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 72,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RELATED)
.add(jPanel1Layout. createParallelGroup (org.j desktop.layout.GroupLayout.LEADING, false)
.add(btnExit, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(btnEdit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 70, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(38, Short.MAX_VALUE))
);
jPanel1Layout. setVerticalGroup( jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnTampil)
.add(btnSave) .add(btnEdit))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(btnDelete)
.add(btnFind) .add(btnExit))
.addContainerGap (org.j desktop . layout. GroupLayout. DEFAULT_SIZE,
Short.MAX_VALUE))
);
org.jdesktop.layout.GroupLayout layout = new org.j desktop . layout. GroupLayout(getContentPane()); getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout. createParallelGroup(org.j desktop.layout. GroupLayout. LEADING) .add(layout.createSequentialGroup()
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout. LEADING)
.add(layout.createSequentialGroup()
.add(45, 45, 45)
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 324,
org.j desktop.layout. GroupLayout. PREFERRED_SIZE))
.add(layout.createSequentialGroup() .add(71, 71, 71)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel 1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.j desktop . layout. GroupLayout. LEADING,
layout. createSequentialGroup()
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(jLabel1)
.add(jLabel3) .add(jLabel5) .add(jLabel4) .add(jLabel6) .add(jLabel7))
.add(24, 24, 24)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(layout.createSequentialGroup()
.add(cmbTgl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 47,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.addPreferredGap(org.j desktop . layout. LayoutStyle .RELATED) .add(cmbBln,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.addPreferredGap(org.j desktop . layout. LayoutStyle .RELATED) .add(cmbThn,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)) .add(layout.createSequentialGroup()
.add(rdLaki)
.addPreferredGap(org.j desktop . layout. LayoutStyle .RELATED) .add(rdPerempuan))
.add(txtNim, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 112,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE)

.add(txtNama, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
.add(txtTempat)
.add(txtAlamat))))))
.addContainerGap(64, Short.MAX_VALUE))
);
layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.j desktop.layout. GroupLayout. PREFERRED_SIZE)
.addPreferredGap(org.j desktop.layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout.BASELINE) .add(j Label 1)
.add(txtNim, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop.layout. GroupLayout. PREFERRED_SIZE))
.addPreferredGap(org.j desktop.layout. LayoutStyle. RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(j Label3)
.add(txtNama, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE))
.add(6, 6, 6)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout.BASELINE) .add(j Label4)
.add(rdLaki)
.add(rdPerempuan))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING) .add(j Label5)
.add(txtTempat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE))
.addPreferredGap(org.j desktop . layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop . layout. GroupLayout. LEADING)
.add(layout.createParallelGroup (org.j desktop . layout. GroupLayout.BASELINE)
.add(cmbBln, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop . layout. GroupLayout. PREFERRED_SIZE)
.add(cmbThn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop . layout. GroupLayout. PREFERRED_SIZE)

.add(cmbTgl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.j desktop.layout. GroupLayout. PREFERRED_SIZE))
.add(jLabel6))
.addPreferredGap(org.j desktop.layout. LayoutStyle. RELATED)
.add(layout. createParallelGroup(org.j desktop.layout. GroupLayout. LEADING) .add(txtAlamat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 66,
org.j desktop.layout. GroupLayout. PREFERRED_SIZE) .add(jLabel7))
.addPreferredGap(org.j desktop.layout. LayoutStyle. UNRELATED) .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.j desktop . layout. GroupLayout. PREFERRED_SIZE) .addContainerGap(33, Short.MAX_VALUE))
);
pack();
} // </editor-fold>
private void txtNimActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
txtNama.requestFocus();
find();
}
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
System.exit(0);
}
private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
delete();
bersih();
}
private void btnEditActionPerformed(j ava.awt.event.ActionEvent evt) { // TODO add your handling code here:
edit();
bersih();
}
private void btnFindActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
find();

}
private void btnTampilActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
tgl_lahir = cmbTgl.getSelectedItem() + "-" + cmbBln.getSelectedItem() + "-" + cmbThn.getSelectedItem() ;
if(rdLaki.isSelected()) {
jenkel="Laki-Laki";
} if(rdPerempuan.isSelected())
{
jenkel="Perempuan";
} JOptionPane.showMessageDialog(null,
txtNim.getText()+"\n"+
txtNama.getText()+"\n"+
jenkel+"\n"+
txtTempat.getText()+"\n"+
tgl_lahir+"\n"+
txtAlmt.getText(),"Tampil",JOptionPane.PLAIN_MESSAGE);
}
private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
save();
bersih();
}
String jenkel,tgl_lahir;
void save(){
tgl_lahir = cmbThn.getSelectedItem() + "-"
+ cmbBln.getSelectedItem() + "-"
+ cmbTgl.getSelectedItem() ;
if(rdLaki.isSelected()) {
jenkel="Laki-Laki";
} if(rdPerempuan.isSelected())
{
jenkel="Perempuan";
}
try{
/*String sqlSave = "INSERT INTO data_mhs VALUES ('" +txtNim.getText()+"', '"
+txtNama.getText()+"', '"
+jenkel+"', '"

+txtTempat.getText()+"', '" +tgl_lahir+"', '"
+txtAlmt.getText()
+"')";*/
String sqlSave = "INSERT INTO data_mhs VALUES ('" +txtNim.getText()+"', '" +txtNama.getText()+"', '" +jenkel+"', '"
+txtTempat.getText()+"', '" +tgl_lahir+"', '"
+txtAlmt.getText()+"')";
DBConnection hubung = new DBConnection(); Connection con = hubung.open_a_Connection(); Statement stm = con.createStatement();
stm.executeUpdate(sqlSave);
JOptionPane. showMessageDialog(null, "Data berhasil disimpan! ","Simpan Data",JOptionPane.INFORMATION_MESSAGE);
} catch(Exception e)
{
JOptionPane. showMessageDialog(null, "Data gagal disimpan! "+e, "Simpan Data",JOptionPane.ERROR_MESSAGE);
} }
void edit() {
tgl_lahir = cmbThn.getSelectedItem() + "-" + cmbBln.getSelectedItem() + "-"
+ cmbTgl.getSelectedItem() ;
if(rdLaki.isSelected()) {
jenkel="Laki-Laki";
} if(rdPerempuan.isSelected())
{
jenkel="Perempuan";
} try{
DBConnection hubung = new DBConnection();
Connection con = hubung.open_a_Connection();
Statement stm = con.createStatement();
String sqlEdit = "UPDATE data_mhs SET nama= '"

+txtNama.getText()+"', jenkel= '"
+jenkel+"', tmpt_lhr= '"
+txtTempat.getText()+"', tgl_lhr= '"
+tgl_lahir+"', alamat= '"
+txtAlmt.getText()+"' WHERE nim='"+txtNim.getText()+"'";
stm.executeUpdate(sqlEdit);
stm.close(); con.close();
JOptionPane. showMessageDialog(null, "Data berhasil di ubah! ","Ubah Data", JOptionPane.INFORMATION_ME S SAGE);
} catch(Exception ex) {
JOptionPane. showMessageDialog(null, "Error 2"+ex);
}
}
void delete(){
try{
String sqlDelete = "DELETE FROM data_mhs WHERE nim='"+txtNim.getText()+"'";
DBConnection hubung = new DBConnection();
Connection con = hubung.open_a_Connection();
Statement stm = con.createStatement();
stm.executeUpdate(sqlDelete);
stm.close(); con.close();
JOptionPane. showMessageDialog(null, "Data Telah Dihapus! ","Hapus Data",JOptionPane.INFORMATION_MESSAGE);
} catch(Exception exc) {
JOptionPane. showMessageDialog(null, "Error 3 "+exc); }
}
void find(){
String sqlFind = "SELECT
nim,nama,jenkel,tmpt_lhr,DATE_FORMAT(tgl_lhr,'%d'),"+ "DATE_FORMAT(tgl_lhr,'%m'),DATE_FORMAT(tgl_lhr,'%Y'),alamat "+ "FROM data_mhs WHERE nim='"+txtNim.getText()+"'";
try{
DBConnection hubung = new DBConnection(); Connection con = hubung.open_a_Connection();

Statement stm = con.createStatement(); ResultSet rs = stm.executeQuery(sqlFind); if(rs.next()) {
//txtNim. setText(rs.getString("nim")); txtNama.setText(rs.getString("nama")); if(rs.getString(3).equals("Laki-Laki")) {
rdLaki.setSelected(true);
}
else if(rs.getString(3).equals("Perempuan")) { rdPerempuan. setSelected(true);
}
txtTempat. setText(rs.getString("tmpt_lhr")); cmbTgl.setSelectedItem(rs.getString(5)); cmbBln.setSelectedItem(rs.getString(6)); cmbThn.setSelectedItem(rs.getString(7)); txtAlmt.setText(rs.getString("alamat"));
}
} catch(Exception e) {
JOptionPane. showMessageDialog(null, "Error 1 "+sqlFind); }
}
void bersih() {
txtNim.setText("");
txtNama.setText("");
rdLaki.setSelected(false);
rdPerempuan.setSelected(false); txtTempat.setText("");
cmbTgl.setSelectedItem("01"); cmbBln.setSelectedItem("01"); cmbThn.setSelectedItem(" 1985"); txtAlmt.setText("");
txtNim.requestFocus();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
new DataMahasiswa(). setVisible(true);
}
});

// Variables declaration - do not modify private javax.swing.JButton btnDelete; private javax.swing.JButton btnEdit; private javax.swing.JButton btnExit; private javax.swing.JButton btnFind; private javax.swing.JButton btnSave; private javax.swing.JButton btnTampil; private javax.swing.JComboBox cmbBln; private javax.swing.JComboBox cmbTgl; private javax.swing.JComboBox cmbThn; private javax.swing.ButtonGroup grpJenkel; private javax.swing.JLabel jLabel1; 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.JPanel jPanel1; private javax.swing.JRadioButton rdLaki; private javax.swing.JRadioButton rdPerempuan;
private javax.swing.JScrollPane txtAlamat; private javax.swing.JTextArea txtAlmt; private javax.swing.JTextField txtNama; private javax.swing.JTextField txtNim; private javax.swing.JTextField txtTempat; // End of variables declaration
}
Contoh program dapat anda dapatkan di asisten labkom, silihkan hubungi asisten yang ada atau ke ruang asisten.

No comments:

Post a Comment

Saya mengharapkan saran dan komentar dari Anda. Namun sangat indah jika Anda ramah dan sopan, serta bijaksana dalam berkomentar. :)

Komentar Terakhir