Assalamualaikum Wr. Wb.
Hai guys, apa kabar? Lama tak menulis, kali ini penulis akan menulis tentang bagaimana cara membuat program data barang untuk perusahaan. Sebelum itu tulisan ini saya buat untuk memenuhi tugas Mata Kuliah Pemrograman 2.
Program Data Barang. Program ini dibuat dengan maksud untuk memudahkan pihak gudang dalam suatu perusahaanbernama PT. ANEKA KARYA CEMERLANG dalam melakukan penginputan, dan pengecekan data barang. Program ini juga terkoneksi dengan database local MySQL, yang mana database tersebut dapat menyimpan data yang telah diinputkan. Data yang telah diinput dapat diedit atau dihapus. Dan juga sebelum memasuki program, user diminta untuk memasukan Username serta Password mereka. Adapun tampilan atau gambaran program yang saya buat adalah sebagai berikut :
1. Source Code Form Login
import com.mysql.jdbc.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import koneksi.koneksi_program;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Bimsss
*/
public class formlogin extends javax.swing.JFrame {
/**
* Creates new form formlogin
*/
public formlogin() {
initComponents();
}
/**
* 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();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
tfuser = new javax.swing.JTextField();
tfpass = new javax.swing.JTextField();
btnlogin = new javax.swing.JButton();
btnregis = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jLabel2.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
jLabel2.setText("USERNAME");
jLabel3.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
jLabel3.setText("PASSWORD");
tfuser.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
tfpass.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnlogin.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnlogin.setText("LOGIN");
btnlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnloginActionPerformed(evt);
}
});
btnregis.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnregis.setText("REGISTRASI");
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()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tfuser)
.addComponent(tfpass)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnregis)
.addComponent(btnlogin))
.addGap(0, 97, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfuser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnlogin)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnregis)
.addContainerGap(34, Short.MAX_VALUE))
);
jLabel1.setFont(new java.awt.Font("MV Boli", 1, 28)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(" PT. ANEKA KARYA CEMERLANG");
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()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 724, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(186, 186, 186)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(125, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>
private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {
try {
Statement statement =(Statement) koneksi_program.getConnection().createStatement();
ResultSet result=statement.executeQuery("select*from tbllogin where "+"Username='"+tfuser.getText()+"'");
if (result.next()){
if (tfpass.getText().equals(result.getString("Password"))){
new data_barang().show();
this.dispose();
}else{
JOptionPane.showMessageDialog(rootPane,"Password salah");
tfpass.setText("");
tfuser.requestFocus();
}
}else{
JOptionPane.showMessageDialog(rootPane,"User Tidak DItemukan");
tfuser.setText("");
tfpass.setText("");
tfuser.requestFocus();
}
}catch (Exception e){
JOptionPane.showMessageDialog(rootPane, "gagal");
} // TODO add your handling code here:
}
/**
* @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(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(formlogin.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 formlogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnlogin;
private javax.swing.JButton btnregis;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JTextField tfpass;
private javax.swing.JTextField tfuser;
// End of variables declaration
}
2. Souce Code Koneksi
package koneksi;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class koneksi_program {
Connection koneksi;
public Connection getConnection(){
try {
koneksi = DriverManager.getConnection("jdbc:mysql://localhost/db_uasjava_bimo","root","");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Koneksi ke database GAGAl", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
return koneksi;
}
}
3. Source Code Data Barang
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Bimsss
*/
public class data_barang extends javax.swing.JFrame {
private DefaultTableModel tabmode;
private void tampil_barang(){
Object[]baris = {"Kode Barang", "Nama Barang", "Tanggal Masuk", "Harga"};
tabmode= new DefaultTableModel(null, baris);
table_barang.setModel(tabmode);
String sql = "select * from tabel_barang order by kode_barang asc";
try {
Connection konek = new koneksi_program().getConnection();
Statement stat = konek.createStatement();
ResultSet hasil = stat.executeQuery(sql);
while (hasil.next()){
String kode_barang = hasil.getString("kode_barang");
String nama_barang = hasil.getString("nama_barang");
String tgl_masuk = hasil.getString("tgl_masuk");
String harga = hasil.getString("harga");
String[]data = {kode_barang, nama_barang, tgl_masuk, harga};
tabmode.addRow(data);
}
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Menampilkan data GAGAL", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
/**
* Creates new form data_barang
*/
public data_barang() {
initComponents();
tampil_barang();
}
/**
* 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();
jScrollPane1 = new javax.swing.JScrollPane();
table_barang = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
b_refresh = new javax.swing.JButton();
b_Simpan = new javax.swing.JButton();
b_Reset = new javax.swing.JButton();
b_Update = new javax.swing.JButton();
b_Delete = new javax.swing.JButton();
tf_kode_barang = new javax.swing.JTextField();
tf_nama_barang = new javax.swing.JTextField();
tf_harga = new javax.swing.JTextField();
c_tgl = new javax.swing.JComboBox<>();
c_bln = new javax.swing.JComboBox<>();
c_thn = new javax.swing.JComboBox<>();
jLabel6 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
table_barang.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
table_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
table_barang.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"
}
));
table_barang.setGridColor(new java.awt.Color(255, 255, 255));
table_barang.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
table_barangMouseClicked(evt);
}
});
jScrollPane1.setViewportView(table_barang);
jLabel2.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel2.setText("Kode Barang");
jLabel3.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel3.setText("Nama Barang");
jLabel4.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel4.setText("Tanggal Masuk");
jLabel5.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel5.setText("Harga");
jPanel3.setBackground(new java.awt.Color(153, 153, 255));
b_refresh.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_refresh.setText("Segarkan Tabel");
b_refresh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_refreshActionPerformed(evt);
}
});
b_Simpan.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Simpan.setText("Simpan");
b_Simpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_SimpanActionPerformed(evt);
}
});
b_Reset.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Reset.setText("Reset");
b_Reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_ResetActionPerformed(evt);
}
});
b_Update.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Update.setText("Edit");
b_Update.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_UpdateActionPerformed(evt);
}
});
b_Delete.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Delete.setText("Hapus");
b_Delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_DeleteActionPerformed(evt);
}
});
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(b_refresh, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addComponent(b_Simpan, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(b_Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46)
.addComponent(b_Update, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44)
.addComponent(b_Delete, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_refresh)
.addComponent(b_Simpan)
.addComponent(b_Reset)
.addComponent(b_Update)
.addComponent(b_Delete))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
tf_kode_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
tf_kode_barang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tf_kode_barangActionPerformed(evt);
}
});
tf_nama_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
tf_harga.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_tgl.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_tgl.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tanggal", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
c_bln.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_bln.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Bulan", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", " " }));
c_thn.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_thn.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tahun", "2020", "2019", "2018", "2017", "2016", "2015", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000" }));
jLabel6.setFont(new java.awt.Font("Sitka Subheading", 0, 12)); // NOI18N
jLabel6.setText("Rp.");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tf_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tf_harga))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(c_tgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(c_bln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(c_thn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(tf_nama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tf_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(tf_nama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(c_tgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_bln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_thn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(tf_harga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3))
);
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
jLabel1.setFont(new java.awt.Font("MV Boli", 1, 28)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(" DATA BARANG PT. ANEKA KARYA CEMERLANG");
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()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, 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()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0))
);
pack();
}// </editor-fold>
private void tf_kode_barangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void b_SimpanActionPerformed(java.awt.event.ActionEvent evt) {
String kode_barang="", nama_barang = "", tgl_masuk="", tgl="", bln="", thn="";
int harga = 0;
kode_barang = tf_kode_barang.getText();
nama_barang = tf_nama_barang.getText();
tgl = c_tgl.getSelectedItem().toString();
bln = c_bln.getSelectedItem().toString();
thn = c_thn.getSelectedItem().toString();
tgl_masuk = thn+"-"+bln+"-"+tgl;
harga = Integer.parseInt(tf_harga.getText());
try {
Connection konek = new koneksi_program().getConnection();
String sql = "insert into tabel_barang values('"+kode_barang+"', '"+nama_barang+"', '"+tgl_masuk+"', '"+harga+"')";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Telah Tersimpan", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Terjadi Kesalahan Saat Menyimpan Data", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void reset(){
tf_kode_barang.setText("");
tf_nama_barang.setText("");
c_tgl.setSelectedIndex(0);
c_bln.setSelectedIndex(0);
c_thn.setSelectedIndex(0);
tf_harga.setText("");
}
private void b_refreshActionPerformed(java.awt.event.ActionEvent evt) {
tampil_barang();
}
private void b_ResetActionPerformed(java.awt.event.ActionEvent evt) {
reset();
}
public ambil_data f_ambil_barang = null;
private void b_UpdateActionPerformed(java.awt.event.ActionEvent evt) {
String kode_barang="", nama_barang = "", tgl_masuk="", tgl="", bln="", thn="";
int harga = 0;
kode_barang = tf_kode_barang.getText();
nama_barang = tf_nama_barang.getText();
tgl = c_tgl.getSelectedItem().toString();
bln = c_bln.getSelectedItem().toString();
thn = c_thn.getSelectedItem().toString();
tgl_masuk = thn+"-"+bln+"-"+tgl;
harga = Integer.parseInt(tf_harga.getText());
try {
Connection konek = new koneksi_program().getConnection();
String sql = "update tabel_barang set "
+ "nama_barang='"+nama_barang+"', "
+ "tgl_masuk='"+tgl_masuk+"', "
+ "harga='"+harga+"'"
+ "where kode_barang='"+kode_barang+"'";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Dirubah", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Data Tidak Dapat Dirubah", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void b_DeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String kode_barang="";
kode_barang = tf_kode_barang.getText();
try {
Connection konek = new koneksi_program().getConnection();
String sql = "delete from tabel_barang where kode_barang='"+kode_barang+"'";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Data Tidak Dapat Dihapus", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void table_barangMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int tabelBarang = table_barang.getSelectedRow();
tf_kode_barang.setText(table_barang.getValueAt(tabelBarang, 0).toString());
tf_nama_barang.setText(table_barang.getValueAt(tabelBarang, 1).toString());
tf_harga.setText(table_barang.getValueAt(tabelBarang, 3).toString());
c_tgl.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(8, 10));
c_bln.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(5, 7));
c_thn.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(0, 4));
}
private void formWindowClosed(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
/**
* @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_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(data_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(data_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(data_barang.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_barang().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton b_Delete;
private javax.swing.JButton b_Reset;
private javax.swing.JButton b_Simpan;
private javax.swing.JButton b_Update;
private javax.swing.JButton b_refresh;
private javax.swing.JComboBox<String> c_bln;
private javax.swing.JComboBox<String> c_tgl;
private javax.swing.JComboBox<String> c_thn;
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.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table_barang;
private javax.swing.JTextField tf_harga;
private javax.swing.JTextField tf_kode_barang;
private javax.swing.JTextField tf_nama_barang;
// End of variables declaration
}
Hai guys, apa kabar? Lama tak menulis, kali ini penulis akan menulis tentang bagaimana cara membuat program data barang untuk perusahaan. Sebelum itu tulisan ini saya buat untuk memenuhi tugas Mata Kuliah Pemrograman 2.
LEMBAR JAWABAN UAS PEMROGRAMAN II
DESKRIPSI PROGRAM
Program Data Barang. Program ini dibuat dengan maksud untuk memudahkan pihak gudang dalam suatu perusahaanbernama PT. ANEKA KARYA CEMERLANG dalam melakukan penginputan, dan pengecekan data barang. Program ini juga terkoneksi dengan database local MySQL, yang mana database tersebut dapat menyimpan data yang telah diinputkan. Data yang telah diinput dapat diedit atau dihapus. Dan juga sebelum memasuki program, user diminta untuk memasukan Username serta Password mereka. Adapun tampilan atau gambaran program yang saya buat adalah sebagai berikut :
SCREEN SHOOT DESAI FRAME/FORM
SOURCE CODE PROGRAM
1. Source Code Form Login
import com.mysql.jdbc.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
import koneksi.koneksi_program;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Bimsss
*/
public class formlogin extends javax.swing.JFrame {
/**
* Creates new form formlogin
*/
public formlogin() {
initComponents();
}
/**
* 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();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
tfuser = new javax.swing.JTextField();
tfpass = new javax.swing.JTextField();
btnlogin = new javax.swing.JButton();
btnregis = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
jPanel3.setBackground(new java.awt.Color(255, 255, 255));
jLabel2.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
jLabel2.setText("USERNAME");
jLabel3.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
jLabel3.setText("PASSWORD");
tfuser.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
tfpass.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnlogin.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnlogin.setText("LOGIN");
btnlogin.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnloginActionPerformed(evt);
}
});
btnregis.setFont(new java.awt.Font("Sitka Subheading", 1, 18)); // NOI18N
btnregis.setText("REGISTRASI");
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()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tfuser)
.addComponent(tfpass)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnregis)
.addComponent(btnlogin))
.addGap(0, 97, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfuser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tfpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnlogin)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnregis)
.addContainerGap(34, Short.MAX_VALUE))
);
jLabel1.setFont(new java.awt.Font("MV Boli", 1, 28)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(" PT. ANEKA KARYA CEMERLANG");
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()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 724, Short.MAX_VALUE)
.addContainerGap())
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(186, 186, 186)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(125, Short.MAX_VALUE))
);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>
private void btnloginActionPerformed(java.awt.event.ActionEvent evt) {
try {
Statement statement =(Statement) koneksi_program.getConnection().createStatement();
ResultSet result=statement.executeQuery("select*from tbllogin where "+"Username='"+tfuser.getText()+"'");
if (result.next()){
if (tfpass.getText().equals(result.getString("Password"))){
new data_barang().show();
this.dispose();
}else{
JOptionPane.showMessageDialog(rootPane,"Password salah");
tfpass.setText("");
tfuser.requestFocus();
}
}else{
JOptionPane.showMessageDialog(rootPane,"User Tidak DItemukan");
tfuser.setText("");
tfpass.setText("");
tfuser.requestFocus();
}
}catch (Exception e){
JOptionPane.showMessageDialog(rootPane, "gagal");
} // TODO add your handling code here:
}
/**
* @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(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(formlogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(formlogin.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 formlogin().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnlogin;
private javax.swing.JButton btnregis;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JTextField tfpass;
private javax.swing.JTextField tfuser;
// End of variables declaration
}
2. Souce Code Koneksi
package koneksi;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JOptionPane;
public class koneksi_program {
Connection koneksi;
public Connection getConnection(){
try {
koneksi = DriverManager.getConnection("jdbc:mysql://localhost/db_uasjava_bimo","root","");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Koneksi ke database GAGAl", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
return koneksi;
}
}
3. Source Code Data Barang
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Bimsss
*/
public class data_barang extends javax.swing.JFrame {
private DefaultTableModel tabmode;
private void tampil_barang(){
Object[]baris = {"Kode Barang", "Nama Barang", "Tanggal Masuk", "Harga"};
tabmode= new DefaultTableModel(null, baris);
table_barang.setModel(tabmode);
String sql = "select * from tabel_barang order by kode_barang asc";
try {
Connection konek = new koneksi_program().getConnection();
Statement stat = konek.createStatement();
ResultSet hasil = stat.executeQuery(sql);
while (hasil.next()){
String kode_barang = hasil.getString("kode_barang");
String nama_barang = hasil.getString("nama_barang");
String tgl_masuk = hasil.getString("tgl_masuk");
String harga = hasil.getString("harga");
String[]data = {kode_barang, nama_barang, tgl_masuk, harga};
tabmode.addRow(data);
}
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Menampilkan data GAGAL", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
/**
* Creates new form data_barang
*/
public data_barang() {
initComponents();
tampil_barang();
}
/**
* 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();
jScrollPane1 = new javax.swing.JScrollPane();
table_barang = new javax.swing.JTable();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
b_refresh = new javax.swing.JButton();
b_Simpan = new javax.swing.JButton();
b_Reset = new javax.swing.JButton();
b_Update = new javax.swing.JButton();
b_Delete = new javax.swing.JButton();
tf_kode_barang = new javax.swing.JTextField();
tf_nama_barang = new javax.swing.JTextField();
tf_harga = new javax.swing.JTextField();
c_tgl = new javax.swing.JComboBox<>();
c_bln = new javax.swing.JComboBox<>();
c_thn = new javax.swing.JComboBox<>();
jLabel6 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
table_barang.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
table_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
table_barang.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"
}
));
table_barang.setGridColor(new java.awt.Color(255, 255, 255));
table_barang.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
table_barangMouseClicked(evt);
}
});
jScrollPane1.setViewportView(table_barang);
jLabel2.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel2.setText("Kode Barang");
jLabel3.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel3.setText("Nama Barang");
jLabel4.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel4.setText("Tanggal Masuk");
jLabel5.setFont(new java.awt.Font("Sitka Subheading", 1, 12)); // NOI18N
jLabel5.setText("Harga");
jPanel3.setBackground(new java.awt.Color(153, 153, 255));
b_refresh.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_refresh.setText("Segarkan Tabel");
b_refresh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_refreshActionPerformed(evt);
}
});
b_Simpan.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Simpan.setText("Simpan");
b_Simpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_SimpanActionPerformed(evt);
}
});
b_Reset.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Reset.setText("Reset");
b_Reset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_ResetActionPerformed(evt);
}
});
b_Update.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Update.setText("Edit");
b_Update.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_UpdateActionPerformed(evt);
}
});
b_Delete.setFont(new java.awt.Font("MV Boli", 1, 14)); // NOI18N
b_Delete.setText("Hapus");
b_Delete.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b_DeleteActionPerformed(evt);
}
});
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(b_refresh, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addComponent(b_Simpan, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(b_Reset, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46)
.addComponent(b_Update, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44)
.addComponent(b_Delete, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(b_refresh)
.addComponent(b_Simpan)
.addComponent(b_Reset)
.addComponent(b_Update)
.addComponent(b_Delete))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
tf_kode_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
tf_kode_barang.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tf_kode_barangActionPerformed(evt);
}
});
tf_nama_barang.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
tf_harga.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_tgl.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_tgl.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tanggal", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
c_bln.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_bln.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Bulan", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", " " }));
c_thn.setFont(new java.awt.Font("Sitka Subheading", 0, 14)); // NOI18N
c_thn.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Tahun", "2020", "2019", "2018", "2017", "2016", "2015", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000" }));
jLabel6.setFont(new java.awt.Font("Sitka Subheading", 0, 12)); // NOI18N
jLabel6.setText("Rp.");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tf_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(tf_harga))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(c_tgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(c_bln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(c_thn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(tf_nama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tf_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(tf_nama_barang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(c_tgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_bln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(c_thn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(tf_harga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(3, 3, 3))
);
jPanel2.setBackground(new java.awt.Color(153, 153, 255));
jLabel1.setFont(new java.awt.Font("MV Boli", 1, 28)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText(" DATA BARANG PT. ANEKA KARYA CEMERLANG");
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()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 775, Short.MAX_VALUE)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, 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()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0))
);
pack();
}// </editor-fold>
private void tf_kode_barangActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void b_SimpanActionPerformed(java.awt.event.ActionEvent evt) {
String kode_barang="", nama_barang = "", tgl_masuk="", tgl="", bln="", thn="";
int harga = 0;
kode_barang = tf_kode_barang.getText();
nama_barang = tf_nama_barang.getText();
tgl = c_tgl.getSelectedItem().toString();
bln = c_bln.getSelectedItem().toString();
thn = c_thn.getSelectedItem().toString();
tgl_masuk = thn+"-"+bln+"-"+tgl;
harga = Integer.parseInt(tf_harga.getText());
try {
Connection konek = new koneksi_program().getConnection();
String sql = "insert into tabel_barang values('"+kode_barang+"', '"+nama_barang+"', '"+tgl_masuk+"', '"+harga+"')";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Telah Tersimpan", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Terjadi Kesalahan Saat Menyimpan Data", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void reset(){
tf_kode_barang.setText("");
tf_nama_barang.setText("");
c_tgl.setSelectedIndex(0);
c_bln.setSelectedIndex(0);
c_thn.setSelectedIndex(0);
tf_harga.setText("");
}
private void b_refreshActionPerformed(java.awt.event.ActionEvent evt) {
tampil_barang();
}
private void b_ResetActionPerformed(java.awt.event.ActionEvent evt) {
reset();
}
public ambil_data f_ambil_barang = null;
private void b_UpdateActionPerformed(java.awt.event.ActionEvent evt) {
String kode_barang="", nama_barang = "", tgl_masuk="", tgl="", bln="", thn="";
int harga = 0;
kode_barang = tf_kode_barang.getText();
nama_barang = tf_nama_barang.getText();
tgl = c_tgl.getSelectedItem().toString();
bln = c_bln.getSelectedItem().toString();
thn = c_thn.getSelectedItem().toString();
tgl_masuk = thn+"-"+bln+"-"+tgl;
harga = Integer.parseInt(tf_harga.getText());
try {
Connection konek = new koneksi_program().getConnection();
String sql = "update tabel_barang set "
+ "nama_barang='"+nama_barang+"', "
+ "tgl_masuk='"+tgl_masuk+"', "
+ "harga='"+harga+"'"
+ "where kode_barang='"+kode_barang+"'";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Dirubah", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Data Tidak Dapat Dirubah", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void b_DeleteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String kode_barang="";
kode_barang = tf_kode_barang.getText();
try {
Connection konek = new koneksi_program().getConnection();
String sql = "delete from tabel_barang where kode_barang='"+kode_barang+"'";
PreparedStatement stat = (PreparedStatement) konek.prepareStatement(sql);
stat.executeUpdate();
JOptionPane.showMessageDialog(null, "Data Berhasil Dihapus", "Informasi", JOptionPane.INFORMATION_MESSAGE);
tampil_barang();
reset();
konek.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Data Tidak Dapat Dihapus", "Informasi", JOptionPane.INFORMATION_MESSAGE);
}
}
private void table_barangMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
int tabelBarang = table_barang.getSelectedRow();
tf_kode_barang.setText(table_barang.getValueAt(tabelBarang, 0).toString());
tf_nama_barang.setText(table_barang.getValueAt(tabelBarang, 1).toString());
tf_harga.setText(table_barang.getValueAt(tabelBarang, 3).toString());
c_tgl.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(8, 10));
c_bln.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(5, 7));
c_thn.setSelectedItem(table_barang.getValueAt(tabelBarang, 2).toString().substring(0, 4));
}
private void formWindowClosed(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
/**
* @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_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(data_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(data_barang.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(data_barang.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_barang().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton b_Delete;
private javax.swing.JButton b_Reset;
private javax.swing.JButton b_Simpan;
private javax.swing.JButton b_Update;
private javax.swing.JButton b_refresh;
private javax.swing.JComboBox<String> c_bln;
private javax.swing.JComboBox<String> c_tgl;
private javax.swing.JComboBox<String> c_thn;
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.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable table_barang;
private javax.swing.JTextField tf_harga;
private javax.swing.JTextField tf_kode_barang;
private javax.swing.JTextField tf_nama_barang;
// End of variables declaration
}
4. Source Code Ambil Data
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Bimsss
*/
public class ambil_data extends javax.swing.JFrame {
public String kode_barang;
public String getKode_Barang() {
return kode_barang;
}
public void itemTerpilih(){
data_barang fDB = new data_barang();
fDB.f_ambil_barang = this;
l_kode_barang.setText(kode_barang);
//fDB.fAB = this;
//txtID.setText(idBrg);
//txtNama.setText(namaBrg);
//txtHarga.setText(hargaBrg);
}
/**
* Creates new form ambil_data
*/
public ambil_data() {
initComponents();
}
/**
* 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() {
l_kode_barang = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
l_kode_barang.setText("l_kode_barang");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(l_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(198, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(75, 75, 75)
.addComponent(l_kode_barang, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(172, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @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(ambil_data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ambil_data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ambil_data.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ambil_data.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 ambil_data().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel l_kode_barang;
// End of variables declaration
}
SCREEN SHOT RUN PROJECT
Demikian tulisan ini saya buat. Semoga hasilnya memuaskan serta bermanfaat bagi para pembaca. Terima kasih.
Komentar
Posting Komentar