You are on page 1of 5

package tabel;

import akademik.*;

import java.awt.HeadlessException;

import java.sql.*;

import javax.swing.*;

public dbmhs() {

initComponents();

Bersih();

Aktif();

TdkAktif();

private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


Aktif();

txtNIM.requestFocus();

private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String NIM = "", Nama = "", Alamat = "", Telpon = "", Email = "", Jurusan = "", Prodi = "";

try{

NIM = txtNIM.getText();

Nama = txtNama.getText();

Alamat = txtAlamat.getText();

Telpon = txtTelpon.getText();

Email = txtEmail.getText();

Jurusan = (String) cmbJur.getSelectedItem();

Prodi = (String) cmbProdi.getSelectedItem();

Class.forName("com.mysql.jdbc.Driver");

Connection cn = DriverManager.getConnection("jdbc:mysql://localhost/dbmhs","root","");

String sql = "Insert into mhs


values('"+NIM+"','"+Nama+"','"+Alamat+"','"+Telpon+"','"+Email+"','"+Jurusan+"','"+Prodi+"')"
;

Statement st = cn.createStatement();

st.executeUpdate(sql);

JOptionPane.showMessageDialog(null,"Data Sudah Disimpan", "Simpan",

JOptionPane.INFORMATION_MESSAGE);
Bersih();

TdkAktif();

catch(ClassNotFoundException | SQLException | HeadlessException e){

JOptionPane.showMessageDialog(null,"Ada Kesalahan Dalam Menyimpan Data Pada :"


+e, "Error",

JOptionPane.INFORMATION_MESSAGE);

private void btnBatalActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Bersih();

TdkAktif();

private void btnKeluarActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

System.exit(0);

public void run() {

new dbmhs().setVisible(true);

}
});

public void Bersih(){

txtNIM.setText("");

txtNama.setText("");

txtAlamat.setText("");

txtTelpon.setText("");

txtEmail.setText("");

cmbJur.setSelectedIndex(0);

cmbProdi.setSelectedItem(".:Pilih:.");

public void Aktif(){

txtNIM.setEditable(true);

txtNama.setEditable(true);

txtAlamat.setEditable(true);

txtTelpon.setEditable(true);

txtEmail.setEditable(true);

cmbJur.setEnabled(true);

cmbProdi.setEnabled(true);

btnTambah.setEnabled(true);

btnSimpan.setEnabled(true);

}
public void TdkAktif(){

txtNIM.setEditable(false);

txtNama.setEditable(false);

txtAlamat.setEditable(false);

txtTelpon.setEditable(false);

txtEmail.setEditable(false);

cmbJur.setEnabled(false);

cmbProdi.setEnabled(false);

btnSimpan.setEnabled(false);

You might also like