LAPORAN
APLIKASI PENGELOLA DATA MAHASISWA
MENGGUNAKAN JAVA NETBEANS
Untuk
Memenuhi Salah Satu Tugas Mata Kuliah Praktikum PBO
Dosen
Pembimbing : Imanaji Hari Sayekti, S.Pd., M.Pd.
Kelompok
1 :
1. Ade
Prasetiawan (17.MI.0001)
2. Fatimah
Nur Cahyati (17.MI.0007)
3. Hasan
Ali Maspur (17.MI.0008)
4. Sarman (17.MI.0015)
5. Setiyo
Aji Anjasmoro (17.MI.0016)
AKADEMI
MANAJEMEN INFORMATIKA
AMIK
PGRI KEBUMEN
2019
A. Tujuan Pembuatan
Tujuan
pembuatan aplikasi pengelola data mahasiswa ini adalah, untuk memenuhi salah
satu tugas praktikum mata kuliah pemrograman berorientasi objek (PBO).
B. Perangkat Lunak (Software) Yang Digunakan
Perangkat
lunak atau software yang digunakan dalam pembuatan
aplikasi ini yaitu:
-
Windows
8.1 Pro 64bit
-
Netbeans
IDE 8.2
-
Library
(MySQL JDBC Driver)
-
Appserv
(Database MySql)
-
Microsoft
Word
C. Perancangan
1. Database
Pada tahap ini, membuat database yang akan kita gunakan dalam aplikasi. Di bawah ini merupakan struktur dari database tersebut.
2. Shourcecode
Setelah membuat database, lanjut ke pembuatan aplikasi menggunakan aplikasi Netbeans. Di bawah ini merupakan shourcecode dari pembuatan aplikasi.
a) Config.java,
digunakan untuk menghubungkan aplikasi dengan database yang akan digunakan.
import
java.sql.Connection;
import
java.sql.DriverManager;
import java.sql.SQLException;
//Config oleh Ade
Prastiawan 17.MI.0001
public class config {
private static Connection mysqlconfig;
public static Connection configDB()throws
SQLException{
try {
String
url="jdbc:mysql://localhost/mahasiswa"; //url atau alamat database
String user="root";
//user atau nama login database
String pass="12345678";
//password database, kosongkan jika tidak ada password ("")
DriverManager.registerDriver(new
com.mysql.jdbc.Driver());
mysqlconfig=DriverManager.getConnection(url, user, pass);
} catch (Exception e) {
System.err.println("Koneksi
gagal! "+e.getMessage()); //perintah menampilkan error pada koneksi
}
return mysqlconfig;
}
|
b) Login.java,
digunakan untuk login/masuk akun pengguna/admin ke menu utama.
import
java.awt.event.ActionEvent;
import
java.awt.event.KeyEvent;
import
java.sql.Connection;
import
java.sql.DriverManager;
import
java.sql.ResultSet;
import
java.sql.SQLException;
import
java.sql.Statement;
import
java.util.logging.Level;
import
java.util.logging.Logger;
import
javax.swing.JOptionPane;
public
class Login extends javax.swing.JFrame {
//Login,
oleh Ade Prastiawan 17.MI.0001
public Login() {
initComponents();
setLocationRelativeTo(null);
}
private void
btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
try {
//memanggil koneksi
Connection kon =
config.configDB();
ResultSet as =
kon.createStatement().executeQuery("select * from tlogin where
username='"+txtUsername.getText()
+"' and
password='"+String.valueOf(txtPass.getPassword())+"'");//menyeleksi
tabel tlogin
if(as.next()){
menu_utama ad = new
menu_utama();//jika berhasil, maka akan bisa akses ke jframe menu utama
ad.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(rootPane,
"Username dan Password yang anda masukkan salah !!!");//pesan jika
error login
}
} catch (SQLException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE,
null, ex);
}
}
private void
btnCancelActionPerformed(java.awt.event.ActionEvent evt) {
// Tombol cancel login
System.exit(0);
}
private void
txtPassKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyCode() ==
KeyEvent.VK_ENTER) {
btnLoginActionPerformed(new
ActionEvent(evt.getSource(), evt.getID(), "Key Press proses"));
}
}
private void
txtUsernameKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyCode() ==
KeyEvent.VK_ENTER) {
btnLoginActionPerformed(new
ActionEvent(evt.getSource(), evt.getID(), "Key Press proses"));
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
new Login().setVisible(true);
}
});
}
}
|
c) Menu_utama.java
import
java.awt.print.PrinterException;
import
java.text.MessageFormat;
import
java.util.logging.Level;
import
java.util.logging.Logger;
import
javax.swing.JOptionPane;
import
javax.swing.JTable;
public
class menu_utama extends javax.swing.JFrame {
public menu_utama() {
initComponents();
setLocationRelativeTo(null);
}
@SuppressWarnings("unchecked")
private void
jInsertActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Insert log = new Insert();
log.setVisible(true);
dispose();
}
private void
jLogoutActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if
(JOptionPane.showConfirmDialog(null, "Yakin mau
keluar?","Option", JOptionPane.YES_NO_OPTION )!=
JOptionPane.YES_OPTION) {
} else {
Login log = new
Login();//memanggil jframe menu_utama
log.setVisible(true);
dispose();
}
}
private void
jHapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Hapus log = new Hapus();
log.setVisible(true);
dispose();
}
private void
jEditActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Edit log = new Edit();
log.setVisible(true);
dispose();
}
private void
jLihatActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Lihat log = new Lihat();;
log.setVisible(true);
dispose();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
new
menu_utama().setVisible(true);
}
});
}
}
|
d) Insert.java
import
java.sql.Connection;
import
javax.swing.JOptionPane;
import
javax.swing.table.DefaultTableModel;
public
class Insert extends javax.swing.JFrame {
//Menu
Insert, Oleh Hasan Ali Maspur 17.MI.0008
public Insert() {
initComponents();
combo();
setLocationRelativeTo(null);
}
private void combo() {
// desain tampilan untuk combobox
jComboBox1.addItem("--Pilih
Jurusan--");
jComboBox1.addItem("Teknik
Informatika");
jComboBox1.addItem("Manajemen
Informatika");
jComboBox1.addItem("Teknik
Sipil");
jComboBox1.addItem("Teknik
Mesin");
}
//kelas untuk mengosongkan seluruh form
private void kosong() {
txt_alamat.setText(null);//null atau
kosong
txt_nama.setText(null);
txt_nim.setText(null);
txt_phone.setText(null);
txt_ktp.setText(null);
txt_semester.setText(null);
jComboBox1.setSelectedItem(null);
}
@SuppressWarnings("unchecked")
private void
btn_clearActionPerformed(java.awt.event.ActionEvent evt) {
//tombol clear
// bersihkan form
kosong();//memanggil class kosong
}
private void
btn_tambahActionPerformed(java.awt.event.ActionEvent evt) {
//string memasukkan data ke table mhs
try {
String sql = "INSERT INTO
mhs VALUES ('" + txt_nama.getText() + "','" +
txt_nim.getText()
+ "','" +
jComboBox1.getSelectedItem() + "','" + txt_alamat.getText() +
"','" + txt_phone.getText()
+ "','" +
txt_ktp.getText() + "','" + txt_semester.getText() +
"')";
java.sql.Connection conn =
(Connection) config.configDB();
java.sql.PreparedStatement pst =
conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Penyimpanan Data
Berhasil");//pesan jika berhasil
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
kosong();
combo();
}
private
void btnKembaliActionPerformed(java.awt.event.ActionEvent evt) {
//tombol kembali
menu_utama log = new
menu_utama();//kembali ke menu utama (akses ke jframe menu_utama)
log.setVisible(true);
dispose();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
new Insert().setVisible(true);
}
});
}
}
|
e) Lihat.java
import
java.awt.event.ActionEvent;
import
java.awt.event.KeyEvent;
import
java.awt.print.PrinterException;
import
java.sql.Connection;
import
java.sql.ResultSet;
import
java.text.MessageFormat;
import
java.text.Normalizer.Form;
import
java.util.logging.Level;
import
java.util.logging.Logger;
import
javax.swing.JTable;
import
javax.swing.RowFilter;
import
javax.swing.table.DefaultTableModel;
import
javax.swing.table.TableRowSorter;
public
class Lihat extends javax.swing.JFrame {
//Menu
Lihat, oleh Setyo Aji Anjasmoro 17.MI.0016
public Lihat() {
initComponents();
load_table();//memanggil load_table
kosong();//memanggil kosong
setLocationRelativeTo(null);
}
private void load_table() {
//membuat tampilan model tabel
mahasiswa
DefaultTableModel model = new
DefaultTableModel();
model.addColumn("No");
model.addColumn("Nama");
model.addColumn("NIM");
model.addColumn("Jurusan");
model.addColumn("Alamat");
model.addColumn("Phone");
model.addColumn("No.KTP");
model.addColumn("Semester");
//menampilkan data database mahasiswa
ke dalam tabel
try {
int no = 1;
String sql = "select * from
mhs where nama like '%" + txtCari.getText() + txtCari.getText() +
"%'";
//menyeleksi atau mengambil data
dari tabel mhs
java.sql.Connection conn =
(Connection) config.configDB();
java.sql.Statement stm =
conn.createStatement();
java.sql.ResultSet res =
stm.executeQuery(sql);
while (res.next()) {
model.addRow(new
Object[]{no++, res.getString(1), res.getString(2), res.getString(3),
res.getString(4),
res.getString(5), res.getString(6), res.getString(7)});
}
jTable1.setModel(model);
} catch (Exception e) {
}
}
//kelas kosong, mengosongkan semua form
private void kosong() {
txt_alamat.setText(null);//null atau
tanpa isi
txt_nama.setText(null);
txt_nim.setText(null);
txt_phone.setText(null);
txt_ktp.setText(null);
txtCari.setText(null);
txt_semester.setText(null);
jJr.setText(null);
}
private void
jTable1MouseClicked(java.awt.event.MouseEvent evt) {
// menampilkan isi data ke dalam form
int baris =
jTable1.rowAtPoint(evt.getPoint());
String nama =
jTable1.getValueAt(baris, 1).toString();
txt_nama.setText(nama);
String nim =
jTable1.getValueAt(baris, 2).toString();
txt_nim.setText(nim);
String jr = jTable1.getValueAt(baris,
3).toString();
jJr.setText(jr);
String alamat =
jTable1.getValueAt(baris, 4).toString();
txt_alamat.setText(alamat);
String telp =
jTable1.getValueAt(baris, 5).toString();
txt_phone.setText(telp);
String ktp = jTable1.getValueAt(baris,
6).toString();
txt_ktp.setText(ktp);
String semester =
jTable1.getValueAt(baris, 7).toString();
txt_semester.setText(semester);
}
private void
btnKembaliActionPerformed(java.awt.event.ActionEvent evt) {
// Tombol kembali
menu_utama log = new
menu_utama();//memanggil jframe menu_utama
log.setVisible(true);
dispose();
}
private void btnCetakActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
try {
jTable1.print(JTable.PrintMode.FIT_WIDTH, new MessageFormat("DATA
MAHASISWA AMIK PGRI KEBUMEN"),null);
} catch (PrinterException ex) {
//Logger.getLogger(Form.Mahasiswa.class.getName()).log(Level.SEVERE,null,
ex);
}
}
private void
btnCariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String cari = txtCari.getText();
cari_data(jTable1, cari);
}
private void
txtCariKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyCode() ==
KeyEvent.VK_ENTER) {
btnCariActionPerformed(new
ActionEvent(evt.getSource(), evt.getID(), "Key Press proses"));
}
}
private void
btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
load_table();
kosong();
}
public void cari_data(JTable tbl, String
text){
TableRowSorter sorter = new
TableRowSorter(tbl.getModel());
tbl.setRowSorter(sorter);
sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
tbl.setSelectionMode(1);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
new Lihat().setVisible(true);
}
});
}
}
|
f) Edit.java
import
java.awt.event.ActionEvent;
import
java.awt.event.KeyEvent;
import
java.sql.Connection;
import
javax.swing.JOptionPane;
import
javax.swing.JTable;
import
javax.swing.RowFilter;
import
javax.swing.table.DefaultTableModel;
import
javax.swing.table.TableRowSorter;
public
class Edit extends javax.swing.JFrame {
//Menu
Edit, oleh Sarman 17.MI.0015
public Edit() {
initComponents();
load_table();//memanggil class
load_table
kosong();//memangggil class kosong
setLocationRelativeTo(null);
}
private void load_table() {
//membuat tampilan model tabel
mahasiswa
DefaultTableModel model = new
DefaultTableModel();
model.addColumn("No");
model.addColumn("Nama");
model.addColumn("NIM");
model.addColumn("Jurusan");
model.addColumn("Alamat");
model.addColumn("Phone");
model.addColumn("No.KTP");
model.addColumn("Semester");
//menampilkan data database mahasiswa
ke dalam tabel
try {
int no = 1;
String sql = "select * from
mhs";//menyeleksi atau mengambil data dari tabel mhs
java.sql.Connection conn =
(Connection) config.configDB();
java.sql.Statement stm =
conn.createStatement();
java.sql.ResultSet res =
stm.executeQuery(sql);
while (res.next()) {
model.addRow(new
Object[]{no++, res.getString(1), res.getString(2), res.getString(3),
res.getString(4),
res.getString(5),
res.getString(6), res.getString(7)});
}
jTable1.setModel(model);
} catch (Exception e) {
}
// desain tampilan untuk menampilkan
pilihan di combobox
jComboBox1.addItem("Teknik
Informatika");
jComboBox1.addItem("Manajemen
Informatika");
jComboBox1.addItem("Teknik
Sipil");
jComboBox1.addItem("Teknik
Mesin");
}
//class kosong, untuk mengosongkan
pilihan/isi pada teksfield atau combo
private void kosong() {
txt_alamat.setText(null);//null atau
kosong
txt_nama.setText(null);
txt_phone.setText(null);
txt_ktp.setText(null);
txt_semester.setText(null);
jComboBox1.setSelectedItem(null);
jNim.setText(null);
txtCari.setText(null);
}
@SuppressWarnings("unchecked")
private void
btn_editActionPerformed(java.awt.event.ActionEvent evt) {
//action tombol edit
//txt_nim.setVisible(false);
try {
//mengupdate data mahasiswa yg di
edit
String sql ="UPDATE mhs SET
nama = '"+txt_nama.getText()+"', jurusan "
+ "=
'"+jComboBox1.getSelectedItem()+"',alamat=
'"+txt_alamat.getText()+"',phone=
'"+txt_phone.getText()+"',ktp"
+ "=
'"+txt_ktp.getText()+"',semester=
'"+txt_semester.getText()+"' WHERE nim =
'"+jNim.getText()+"'";
java.sql.Connection
conn=(Connection)config.configDB();
java.sql.PreparedStatement
pst=conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(null, "Data berhasil di
edit");//menampilkan pesan jika berhasil diedit
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Perubahan Data
Gagal"+e.getMessage());//pesan gagal jika error
}
load_table();//memanggil class tabel
kosong();//memanggil class kosong
}
private void
btn_clearActionPerformed(java.awt.event.ActionEvent evt) {
//action tombol clear
//membersihkan seluruh form
kosong();
//memanggil class kosong
load_table();
}
private void
jTable1MouseClicked(java.awt.event.MouseEvent evt) {
//menampilkan data ke form agar bisa
di edit
int baris =
jTable1.rowAtPoint(evt.getPoint());
String nama =
jTable1.getValueAt(baris, 1).toString();
txt_nama.setText(nama);
String nim =
jTable1.getValueAt(baris, 2).toString();
jNim.setText(nim);
String jr = jTable1.getValueAt(baris,
3).toString();
jComboBox1.setSelectedItem(jr);
String alamat =
jTable1.getValueAt(baris, 4).toString();
txt_alamat.setText(alamat);
String telp =
jTable1.getValueAt(baris, 5).toString();
txt_phone.setText(telp);
String ktp =
jTable1.getValueAt(baris, 6).toString();
txt_ktp.setText(ktp);
String semester =
jTable1.getValueAt(baris, 7).toString();
txt_semester.setText(semester);
}
private void
btnKembaliActionPerformed(java.awt.event.ActionEvent evt) {
//tombol kembali
menu_utama log = new
menu_utama();//kembali ke menu utama
log.setVisible(true);
dispose();
}
public void cari_data(JTable tbl, String
text){
TableRowSorter sorter = new
TableRowSorter(tbl.getModel());
tbl.setRowSorter(sorter);
sorter.setRowFilter(RowFilter.regexFilter("(?i)"
+ text));
tbl.setSelectionMode(1);
}
private void
txtCariKeyPressed(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
if (evt.getKeyCode() ==
KeyEvent.VK_ENTER) {
btnCariActionPerformed(new
ActionEvent(evt.getSource(), evt.getID(), "Key Press proses"));
}
}
private void
btnCariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String cari = txtCari.getText();
cari_data(jTable1, cari);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new
Runnable() {
public void run() {
new Edit().setVisible(true);
}
});
}
}
|
g) Hapus.java
import
java.awt.event.ActionEvent;
import
java.awt.event.KeyEvent;
import
java.sql.Connection;
import
javax.swing.JOptionPane;
import
javax.swing.JTable;
import
javax.swing.RowFilter;
import
javax.swing.table.DefaultTableModel;
import
javax.swing.table.TableRowSorter;
public
class Hapus extends javax.swing.JFrame {
//Menu
Hapus, oleh Fatimah Nur Cahyawati 17.MI.0007
public Hapus() {
initComponents();
load_table();//memanggil class
load_table
kosong();//memanggil class kosong
setLocationRelativeTo(null);
}
private void load_table() {
//membuat tampilan model tabel
mahasiswa
DefaultTableModel model = new
DefaultTableModel();
model.addColumn("No");
model.addColumn("Nama");
model.addColumn("NIM");
model.addColumn("Jurusan");
model.addColumn("Alamat");
model.addColumn("Phone");
model.addColumn("No.KTP");
model.addColumn("Semester");
//menampilkan data database mahasiswa
ke dalam tabel
try {
int no = 1;
String sql = "select * from
mhs";//menyeleksi atau mengambil data dari tabel mhs
java.sql.Connection conn =
(Connection) config.configDB();
java.sql.Statement stm =
conn.createStatement();
java.sql.ResultSet res =
stm.executeQuery(sql);
while (res.next()) {
model.addRow(new
Object[]{no++, res.getString(1), res.getString(2), res.getString(3),
res.getString(4),
res.getString(5),
res.getString(6), res.getString(7)});
}
jTable1.setModel(model);
} catch (Exception e) {
}
}
//class kosong, untuk mengosongkan
pilihan/isi pada teksfield atau combo
private void kosong() {
txt_alamat.setText(null);
txt_nama.setText(null);//null atau
kosong
txt_nim.setText(null);
txt_phone.setText(null);
txt_ktp.setText(null);
txt_semester.setText(null);
jJr.setText(null);
}
@SuppressWarnings("unchecked")
private void
btn_hapusActionPerformed(java.awt.event.ActionEvent evt) {
//aksi tombol hapus
try {
String sql ="delete from mhs
where nim='"+txt_nim.getText()+"'";//menghapus data dari tabel
mhs
java.sql.Connection
conn=(Connection)config.configDB();
java.sql.PreparedStatement
pst=conn.prepareStatement(sql);
pst.execute();
JOptionPane.showMessageDialog(this, "Berhasil di
hapus");//pesan jika berhasil
} catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage());
}
load_table();//memanggil class
load_table
kosong();//memanggil class kosong
}
private void
jTable1MouseClicked(java.awt.event.MouseEvent evt) {
////menampilkan data ke form
int baris =
jTable1.rowAtPoint(evt.getPoint());
String nama = jTable1.getValueAt(baris,
1).toString();
txt_nama.setText(nama);
String nim =
jTable1.getValueAt(baris, 2).toString();
txt_nim.setText(nim);
String jr = jTable1.getValueAt(baris,
3).toString();
jJr.setText(jr);
String alamat =
jTable1.getValueAt(baris, 4).toString();
txt_alamat.setText(alamat);
String telp =
jTable1.getValueAt(baris, 5).toString();
txt_phone.setText(telp);
String ktp =
jTable1.getValueAt(baris, 6).toString();
txt_ktp.setText(ktp);
String semester =
jTable1.getValueAt(baris, 7).toString();
txt_semester.setText(semester);
}
private void
btnKembaliActionPerformed(java.awt.event.ActionEvent evt) {
//tombol kembali
menu_utama log = new
menu_utama();//menuju menu utama
log.setVisible(true);
dispose();
}
private void btnCariActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
String cari = txtCari.getText();
cari_data(jTable1, cari);
}
private void txtCariKeyPressed(java.awt.event.KeyEvent
evt) {
// TODO add your handling code here:
if (evt.getKeyCode() ==
KeyEvent.VK_ENTER) {
btnCariActionPerformed(new
ActionEvent(evt.getSource(), evt.getID(), "Key Press proses"));
}
}
public void cari_data(JTable tbl, String
text){
TableRowSorter sorter = new
TableRowSorter(tbl.getModel());
tbl.setRowSorter(sorter);
sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text));
tbl.setSelectionMode(1);
}
public static void main(String args[]) {
}
|
3. Desain
Pada tahap ini merupakan desain dari aplikasi yang akan dibuat.
a) Desain
Login
b) Desain
Menu Utama
c) Desain
Memasukan/Insert Data
d) Desain
Melihat Data Mahasiswa
e) Desain
Mengedit Data Mahasiswa
f) Desain
Menghapus Data Mahasiswa
D. Pembahasan Aplikasi
Setelah tahap di atas, dii bawah ini merupakan tampilan dari aplikasi yang telah dibuat.
1. Login
2. Menu
Utama
3. Memasukan
Data Mahasiswa
4. Melihat
Data Mahasiswa
5. Mengedit
Data Mahasiswa
6. Menghapus
Data Mahasiswa
7. Mencetak
Data Mahasiswa
8. Logout
Terimakasih telah membaca artikel ini, semoga bermanfaat.
Belum ada tanggapan untuk "Aplikasi Pengelola Data Mahasiswa Menggunakan Java Netbeans"
Posting Komentar