Source Code Aplikasi Input Data Mahasiswa
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* Data_Mahasiswa.java
*
* Created on Dec 17, 2015, 4:09:50 PM
*/
package aplikasi;
import com.mysql.jdbc.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Server
*/
public class Data_Mahasiswa extends javax.swing.JFrame {
/** Creates new form Data_Mahasiswa */
public Data_Mahasiswa() {
initComponents();
datatable();
}
/** 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">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
Txtnim = new javax.swing.JTextField();
txtnama = new javax.swing.JTextField();
txtalamat = new javax.swing.JTextField();
cmbjur = new javax.swing.JComboBox();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
btambah = new javax.swing.JButton();
bsimpan = new javax.swing.JButton();
bcari = new javax.swing.JButton();
bhapus = new javax.swing.JButton();
bkeluar = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
tabel = new javax.swing.JTable();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(-16711681,true));
cmbjur.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Teknik Informatika", "Sistem Komputer", "Akuntansi", "Manajemen" }));
cmbjur.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbjurActionPerformed(evt);
}
});
jRadioButton1.setText("Laki - laki");
jRadioButton2.setText("Wanita");
btambah.setText("Tambah");
btambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btambahActionPerformed(evt);
}
});
bsimpan.setText("Simpan");
bsimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bsimpanActionPerformed(evt);
}
});
bcari.setText("cari");
bcari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bcariActionPerformed(evt);
}
});
bhapus.setText("Hapus");
bhapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bhapusActionPerformed(evt);
}
});
bkeluar.setText("Keluar");
bkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bkeluarActionPerformed(evt);
}
});
tabel.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane1.setViewportView(tabel);
jLabel1.setText("NIM");
jLabel2.setText("Nama Mahasiswa");
jLabel3.setText("Jurusan");
jLabel4.setText("Jenis Kelamin");
jLabel5.setText("Alamat");
jLabel6.setText("Proses__________________________________________________________________________________");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addGap(43, 43, 43)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
.addComponent(txtalamat, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jRadioButton1)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(cmbjur, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Txtnim, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
.addComponent(txtnama, javax.swing.GroupLayout.Alignment.LEADING))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(90, 90, 90)
.addComponent(btambah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bsimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bcari, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bhapus)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(bkeluar))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(14, 14, 14)
.addComponent(jLabel6))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 530, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Txtnim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cmbjur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3))
.addGap(5, 5, 5)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(jLabel4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtalamat, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(3, 3, 3)
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bkeluar)
.addComponent(bhapus)
.addComponent(bcari)
.addComponent(bsimpan)
.addComponent(btambah))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jLabel7.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
jLabel7.setText("Input Data Mahsiswa");
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()
.addGap(159, 159, 159)
.addComponent(jLabel7))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void cmbjurActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btambahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Txtnim.setText("");
txtnama.setText("");
cmbjur.setSelectedItem("");
if(jRadioButton1.isSelected()){
JOptionPane.showMessageDialog(rootPane, "Laki - laki");
}else if(jRadioButton2.isSelected()){
JOptionPane.showMessageDialog(rootPane, "Wanita");
txtalamat.setText("");
}
}
private void bsimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String nim = Txtnim.getText();
String nama = txtnama.getText();
String jurusan = (String) cmbjur.getSelectedItem();
String alamat = txtalamat.getText();
String jeniskelamin = null;
if(jRadioButton1.isSelected()){
jeniskelamin="Laki - laki";
}else if(jRadioButton2.isSelected()){
jeniskelamin="wanita";
}
try {
Statement statement = (Statement) koneksi.getConnection().createStatement();
statement.executeUpdate("insert into mahasiswa values ('"+nim+"','"+nama+"','"+jeniskelamin+"','"+jurusan+"','"+alamat+"')");
statement.close();
JOptionPane.showMessageDialog(rootPane, "Berhasil Simpan");
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Tidak Berhasil Disimpan");
}
datatable();
}
private void bcariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void bhapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String nim = Txtnim.getText();
try {
Statement statement = (Statement) koneksi.getConnection().createStatement();
statement.executeUpdate("delete from mahasiswa where nim=('"+nim+"');");
JOptionPane.showMessageDialog(rootPane, "Berhasil di hapus");
Txtnim.setText("");
txtnama.setText("");
cmbjur.setSelectedItem("");
txtalamat.setText("");
Txtnim.requestFocus();
} catch (Exception e) {
JOptionPane.showMessageDialog(rootPane, "Gagal Hapus");
}
datatable();
}
private void bkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
/**
* @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(Data_Mahasiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Data_Mahasiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Data_Mahasiswa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Data_Mahasiswa.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 Data_Mahasiswa().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Txtnim;
private javax.swing.JButton bcari;
private javax.swing.JButton bhapus;
private javax.swing.JButton bkeluar;
private javax.swing.JButton bsimpan;
private javax.swing.JButton btambah;
private javax.swing.JComboBox cmbjur;
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 jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tabel;
private javax.swing.JTextField txtalamat;
private javax.swing.JTextField txtnama;
// End of variables declaration
private void datatable() {
DefaultTableModel tbl=new DefaultTableModel();
tbl.addColumn("NIM");
tbl.addColumn("Nama");
tbl.addColumn("Jenis Kelamin");
tbl.addColumn("Jurusan");
tbl.addColumn("Alamat");
tabel.setModel(tbl);
try{
Statement statement=(Statement)koneksi.getConnection().createStatement();
ResultSet res=statement.executeQuery("select * from mahasiswa");
while(res.next())
{
tbl.addRow(new Object[]{
res.getInt("nim"),
res.getInt("nama"),
res.getInt("jenis_kelamin"),
res.getInt("jurusan"),
res.getInt("alamat")
});
tabel.setModel(tbl);
}
}catch(Exception e){
JOptionPane.showMessageDialog(rootPane, "Koneksi Berhasil");
}
}
}
0 Komentar untuk "Membuat Aplikasi Input Data Mahasiswa Dengan Netbeans"