Download Aplikasi Perpustakaan Java Netbeans
Aplikasi Perpustakaan Java Netbeans
ini adalah projek aplikasi perpustakaan berbasig desktop java netbeans ,
silahkan bisa kalian lihat di bawah ini.
ini adalah salah satu koding diatas download full nya di bawah salah satu link ini ;
public class anggota extends javax.swing.JFrame {
private DefaultTableModel anggota;
public anggota() {
initComponents();
anggota=new DefaultTableModel();
tb_anggota.setModel(anggota);
anggota.addColumn("No");
anggota.addColumn("Kode");
anggota.addColumn("Nama Anggota");
anggota.addColumn("Jenis Kelamin");
anggota.addColumn("No.Hp");
anggota.addColumn("Alamat");
BacaTabelAnggota();
}
private void BacaTabelAnggota(){
anggota.getDataVector().removeAllElements();
try{
String sql = "SELECT * FROM anggota order by kd_anggota";
Statement st = (Statement) koneksi.setKoneksi().createStatement();
ResultSet rs = st.executeQuery(sql);
int no=1;
while (rs.next()){
Object[] dataanggota = new Object[6];
dataanggota[0] = no;
dataanggota[1] = rs.getString("kd_anggota");
dataanggota[2] = rs.getString("nm_anggota");
dataanggota[3] = rs.getString("jk");
dataanggota[4] = rs.getString("no_hp");
dataanggota[5] = rs.getString("alamat");
no=no+1;
anggota.addRow(dataanggota);
}
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void CariAnggota(){
anggota.getDataVector().removeAllElements();
try{
if (ccari.getSelectedItem()=="KODE ANGGOTA")
{
String sql = "SELECT * FROM anggota WHERE kd_anggota LIKE '%"+ tcari.getText()+"%'";
Statement st = (Statement) koneksi.setKoneksi().createStatement();
ResultSet rs = st.executeQuery(sql);
int no=1;
while (rs.next()){
Object[] dataanggota = new Object[6];
dataanggota[0] = no;
dataanggota[1] = rs.getString("kd_anggota");
dataanggota[2] = rs.getString("nm_anggota");
dataanggota[3] = rs.getString("jk");
dataanggota[4] = rs.getString("no_hp");
dataanggota[5] = rs.getString("alamat");
no=no+1;
anggota.addRow(dataanggota);
}
}
else if (ccari.getSelectedItem()=="NAMA ANGGOTA")
{
String sql = "SELECT * FROM anggota WHERE nm_anggota LIKE '%"+ tcari.getText()+"%'";
Statement st = (Statement) koneksi.setKoneksi().createStatement();
ResultSet rs = st.executeQuery(sql);
int no=1;
while (rs.next()){
Object[] dataanggota = new Object[6];
dataanggota[0] = no;
dataanggota[1] = rs.getString("kd_anggota");
dataanggota[2] = rs.getString("nm_anggota");
dataanggota[3] = rs.getString("jk");
dataanggota[4] = rs.getString("no_hp");
dataanggota[5] = rs.getString("alamat");
no=no+1;
anggota.addRow(dataanggota);
}
}
else if (ccari.getSelectedItem()=="JENIS KELAMIN")
{
String sql = "SELECT * FROM anggota WHERE jk LIKE '%"+ tcari.getText()+"%'";
Statement st = (Statement) koneksi.setKoneksi().createStatement();
ResultSet rs = st.executeQuery(sql);
int no=1;
while (rs.next()){
Object[] dataanggota = new Object[6];
dataanggota[0] = no;
dataanggota[1] = rs.getString("kd_anggota");
dataanggota[2] = rs.getString("nm_anggota");
dataanggota[3] = rs.getString("jk");
dataanggota[4] = rs.getString("no_hp");
dataanggota[5] = rs.getString("alamat");
no=no+1;
anggota.addRow(dataanggota);
}
}
else if (ccari.getSelectedItem()=="STATUS")
{
String sql = "SELECT * FROM anggota WHERE status LIKE '%"+ tcari.getText()+"%'";
Statement st = (Statement) koneksi.setKoneksi().createStatement();
ResultSet rs = st.executeQuery(sql);
int no=1;
while (rs.next()){
Object[] dataanggota = new Object[6];
dataanggota[0] = no;
dataanggota[1] = rs.getString("kd_anggota");
dataanggota[2] = rs.getString("nm_anggota");
dataanggota[3] = rs.getString("jk");
dataanggota[4] = rs.getString("no_hp");
dataanggota[5] = rs.getString("alamat");
no=no+1;
anggota.addRow(dataanggota);
}
}
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void SetTabel()
{
int row=tb_anggota.getSelectedRow();
tkd_anggota.setText((String) tb_anggota.getValueAt(row, 1));
tnm_anggota.setText((String) tb_anggota.getValueAt(row, 2));
jk.setSelectedItem((String) tb_anggota.getValueAt(row, 3));
thp.setText((String) tb_anggota.getValueAt(row, 4));
talamat.setText((String) tb_anggota.getValueAt(row, 5));
}
private void Bersih()
{
tkd_anggota.setText("");
tnm_anggota.setText("");
jk.setSelectedItem("");
thp.setText("");
talamat.setText("");
}
private void Aktif()
{
tkd_anggota.setEnabled(false);
tnm_anggota.setEnabled(true);
jk.setEnabled(true);
thp.setEnabled(true);
talamat.setEnabled(true);
}
private void Nonaktif()
{
tkd_anggota.setEnabled(false);
tnm_anggota.setEnabled(false);
jk.setEnabled(false);
thp.setEnabled(false);
talamat.setEnabled(false);
}
public Date date=new Date();
public SimpleDateFormat kdformat=new SimpleDateFormat ("yyMM");
public String Kode()
{
String urutan=null;
try{
Statement st = (Statement) koneksi.setKoneksi().createStatement();
String sql ="select right (kd_anggota,3)+1 from anggota as kode order by kd_anggota desc";
ResultSet rs = st.executeQuery(sql);
if (rs.next())
{
urutan=rs.getString(1);
while (urutan.length()<3)
urutan="0"+urutan;
urutan=kdformat.format(date)+urutan;
}
else
{
urutan=kdformat.format(date)+"001";
}
}
catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
return urutan;
}
private void SimpanData()
{
try{
String sql = "INSERT INTO anggota VALUES (?,?,?,?,?)";
PreparedStatement prep=(PreparedStatement) koneksi.setKoneksi().prepareStatement(sql);
prep.setString(1,""+tkd_anggota.getText());
prep.setString(2,""+tnm_anggota.getText());
prep.setString(3,""+jk.getSelectedItem());
prep.setString(4,""+thp.getText());
prep.setString(5,""+talamat.getText());
prep.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Disimpan");
BacaTabelAnggota();
Bersih();
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void UpdateData()
{
try{
String sql = "UPDATE anggota set nm_anggota=?, jk=?, no_hp=?, alamat=? WHERE kd_anggota=?";
PreparedStatement prep=(PreparedStatement) koneksi.setKoneksi().prepareStatement(sql);
prep.setString(1,""+tnm_anggota.getText());
prep.setString(2,""+jk.getSelectedItem());
prep.setString(3,""+thp.getText());
prep.setString(4,""+talamat.getText());
prep.setString(5,""+tkd_anggota.getText());
prep.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Diedit");
BacaTabelAnggota();
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
private void HapusData()
{
try{
Statement stat = (Statement) koneksi.setKoneksi().createStatement();
String sql = "DELETE from anggota where kd_anggota=?";
PreparedStatement prep=(PreparedStatement) koneksi.setKoneksi().prepareStatement(sql);
prep.setString(1,""+tkd_anggota.getText());
prep.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus");
BacaTabelAnggota();
Bersih();
}catch(SQLException err){
JOptionPane.showMessageDialog(null,err.getMessage());
}
}
/**
* 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() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
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();
tkd_anggota = new javax.swing.JTextField();
tnm_anggota = new javax.swing.JTextField();
thp = new javax.swing.JTextField();
talamat = new javax.swing.JTextField();
jk = new javax.swing.JComboBox();
btambah = new javax.swing.JButton();
bkeluar = new javax.swing.JButton();
jPanel2 = new javax.swing.JPanel();
jLabel8 = new javax.swing.JLabel();
ccari = new javax.swing.JComboBox();
tcari = new javax.swing.JTextField();
jPanel3 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tb_anggota = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(44, 62, 80));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setText("ANGGOTA PERPUSTAKAAN");
jPanel1.setBackground(new java.awt.Color(31, 58, 147));
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "DATA ANGGOTA", 0, 0, new java.awt.Font("Tahoma", 1, 11), java.awt.Color.white)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setText("Kode Anggota");
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setText("Nama Anggota");
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setText("Jenis Kelamin");
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setText("No. Hp");
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setText("Alamat");
tnm_anggota.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
tnm_anggotaKeyPressed(evt);
}
});
thp.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
thpKeyPressed(evt);
}
});
talamat.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
talamatKeyPressed(evt);
}
});
jk.setForeground(new java.awt.Color(31, 58, 147));
jk.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Laki-Laki", "Perempuan" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tkd_anggota)
.addComponent(tnm_anggota)
.addComponent(thp)
.addComponent(talamat)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel4)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jk, 0, 252, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(5, 5, 5)
.addComponent(tkd_anggota)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3)
.addGap(4, 4, 4)
.addComponent(tnm_anggota)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jk, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(9, 9, 9)
.addComponent(jLabel5)
.addGap(2, 2, 2)
.addComponent(thp, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6)
.addGap(3, 3, 3)
.addComponent(talamat, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
btambah.setForeground(new java.awt.Color(31, 58, 147));
btambah.setText("TAMBAH");
btambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btambahActionPerformed(evt);
}
});
bkeluar.setForeground(new java.awt.Color(31, 58, 147));
bkeluar.setText("KELUAR");
bkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bkeluarActionPerformed(evt);
}
});
jPanel2.setBackground(new java.awt.Color(37, 116, 169));
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "CARI ANGGOTA", 0, 0, new java.awt.Font("Tahoma", 1, 11), java.awt.Color.white)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setText("Cari Berdasarkan ");
ccari.setForeground(new java.awt.Color(31, 58, 147));
ccari.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KODE ANGGOTA", "NAMA ANGGOTA", "JENIS KELAMIN" }));
tcari.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tcariActionPerformed(evt);
}
});
tcari.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
tcariKeyPressed(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ccari, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(tcari))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8)
.addComponent(ccari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tcari, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3.setBackground(new java.awt.Color(37, 116, 169));
jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());
tb_anggota.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"
}
));
tb_anggota.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
tb_anggotaMouseClicked(evt);
}
});
tb_anggota.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
tb_anggotaKeyPressed(evt);
}
});
jScrollPane1.setViewportView(tb_anggota);
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 547, Short.MAX_VALUE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addComponent(btambah, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(bkeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, 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.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addComponent(jLabel1)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bkeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btambah, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void tcariActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void tcariKeyPressed(java.awt.event.KeyEvent evt) {
CariAnggota();
}
private void btambahActionPerformed(java.awt.event.ActionEvent evt) {
if(btambah.getText().equals("TAMBAH"))
{
tkd_anggota.setText(Kode());
btambah.setText("SIMPAN");
bkeluar.setText("BATAL");
Aktif();
tnm_anggota.requestFocus();
}
else if(btambah.getText().equals("SIMPAN"))
{
SimpanData();
BacaTabelAnggota();
btambah.setText("TAMBAH");
bkeluar.setText("KELUAR");
Bersih();
Nonaktif();
}
else if(btambah.getText().equals("UPDATE"))
{
UpdateData();
BacaTabelAnggota();
btambah.setText("TAMBAH");
bkeluar.setText("KELUAR");
Bersih();
Nonaktif();
}
}
jika kalian ingin aplikasi yang sudah jadi silahkan download di bawah ini ;
nah semoga bermanfaat terimakasih..
Komentar
Posting Komentar