NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
* 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.
*/
package pos;

import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author Indana Rishi
*/
public class FrmKonsumen extends javax.swing.JFrame {

koneksi k;
Statement statement;
ResultSet resultset;
int pil;
/**
* Creates new form FrmKonsumen
*/
public FrmKonsumen() {
initComponents();
k = new koneksi();
tampilIcon();
tampilTabel();
}

private void tampilIcon(){
BtnTambah.setIcon(new
ImageIcon("./gambar/plus.png"));
BtnKoreksi.setIcon(new
ImageIcon("./gambar/koreksi.png"));
BtnHapus.setIcon(new
ImageIcon("./gambar/eraser.png"));
BtnSimpan.setIcon(new
ImageIcon("./gambar/save.png"));
BtnBatal.setIcon(new
ImageIcon("./gambar/batal.png"));
BtnKeluar.setIcon(new ImageIcon("./gambar/door.png"));
}

private void simpanData(){
String sql_insert = "insert into konsumen values('"+jLabel1.getText()+"','"+ jLabel2.getText()+"','"+jLabel3.getText()+"','"+jLabel4.getText()+"','"+jLabel5.getText()+"','"+jLabel6.getText()+"')";
try {
statement.executeUpdate(sql_insert);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void koreksiData(){
String sql_edit = "update konsumen set namakonsumen='"+jLabel2.getText()+"', alamatkonsumen='"+jLabel3.getText()+"',kotakonsumen='"+jLabel4.getText()+"', telpkonsumen='"+ jLabel5.getText()+"',hpkonsumen='"+jLabel6.getText()+"' where kodekonsumen='"+jLabel1.getText()+"'";
try {
statement.executeUpdate(sql_edit);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void hapusData(){
String sql_delete = "delete from konsumen where kodekonsumen='"+jLabel1.getText()+"'";
try {
statement.executeUpdate(sql_delete);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void bersih(){
jLabel1.setText(null);
jLabel2.setText(null);
jLabel3.setText(null);
jLabel4.setText(null);
jLabel5.setText(null);
jLabel6.setText(null);
}

private void setTombol(boolean xTambah,boolean xKoreksi,boolean xHapus,boolean xSimpan,boolean xBatal,boolean xKeluar){
BtnTambah.setEnabled(xTambah);
BtnKoreksi.setEnabled(xKoreksi);
BtnHapus.setEnabled(xHapus);
BtnSimpan.setEnabled(xSimpan);
BtnBatal.setEnabled(xBatal);
BtnKeluar.setEnabled(xKeluar);
}

private void setEdit(boolean yKode,boolean yNama,boolean yAlamat,boolean yKota,boolean yTelp,boolean yHP){
jLabel1.setEnabled(yKode);
jLabel2.setEnabled(yNama);
jLabel3.setEnabled(yAlamat);
jLabel4.setEnabled(yKota);
jLabel5.setEnabled(yTelp);
jLabel6.setEnabled(yHP);
}

private void tampilTabel(){
Object
header[]={"Kode","Nama","Alamat","Kota","Telp.","HP"};
DefaultTableModel modelKonsumen = new
DefaultTableModel(null,header)
{
@Override
// Membuat jTable read only
public boolean isCellEditable(int row, int column)
{
return false;
}
};
tabelKonsumen.setModel(modelKonsumen);
int baris = tabelKonsumen.getRowCount();
for (int i = 0; i < baris; i++) {
modelKonsumen.removeRow(i);
}
String sql_select = "select * from konsumen";
try {
statement = k.con.createStatement();
ResultSet resultSet = statement.executeQuery(sql_select);

while(resultSet.next()){
String kode = resultSet.getString(1);
String nama = resultSet.getString(2);
String alamat = resultSet.getString(3);
String kota = resultSet.getString(4);
String telp = resultSet.getString(5);
String hp = resultSet.getString(6);
String kolom[] = {kode,nama,alamat,kota,telp,hp};
modelKonsumen.addRow(kolom);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}

private void tabelKonsumenMouseClicked(java.awt.event.MouseEvent
evt) {
// TODO add your handling code here:
if (pil==2 || pil==3){
jLabel1.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 0).toString());
jLabel2.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 1).toString());
jLabel3.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 2).toString());
jLabel4.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 3).toString());
jLabel5.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 4).toString());
jLabel6.setText(tabelKonsumen.getValueAt(tabelKonsumen.getSelectedRow(), 5).toString());
}
if (pil == 2) {
setEdit(false, true, true, true, true, true);
BtnSimpan.setEnabled(true);
jLabel2.requestFocus();
}
if (pil == 3) {
jLabel1.setEnabled(false);
int opsi = JOptionPane.showConfirmDialog(null, "Benarkah anda ingin menghapus data ini ?", "Penghapusan Data", JOptionPane.YES_NO_OPTION);
if (opsi == JOptionPane.YES_OPTION){
hapusData();
}
tampilTabel();
setTombol(true, true, true, false, false, true);
setEdit(false, false, false, false, false, false);
bersih();
pil=5;
BtnTambah.requestFocus();
}
}


/**
* 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();
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();
mKodeKonsumen = new javax.swing.JTextField();
mNamaKonsumen = new javax.swing.JTextField();
mAlamatKonsumen = new javax.swing.JTextField();
mKotaKonsumen = new javax.swing.JTextField();
mTelpKonsumen = new javax.swing.JTextField();
mHPKonsumen = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
tabelKonsumen = new javax.swing.JTable();
BtnTambah = new javax.swing.JButton();
BtnKoreksi = new javax.swing.JButton();
BtnHapus = new javax.swing.JButton();
BtnSimpan = new javax.swing.JButton();
BtnBatal = new javax.swing.JButton();
BtnKeluar = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Kode");

jLabel2.setText("Nama");

jLabel3.setText("Alamat");

jLabel4.setText("Kota");

jLabel5.setText("Telp");

jLabel6.setText("HP");

mKodeKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mKodeKonsumenActionPerformed(evt);
}
});

mNamaKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mNamaKonsumenActionPerformed(evt);
}
});

mAlamatKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mAlamatKonsumenActionPerformed(evt);
}
});

mKotaKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mKotaKonsumenActionPerformed(evt);
}
});

mTelpKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mTelpKonsumenActionPerformed(evt);
}
});

mHPKonsumen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mHPKonsumenActionPerformed(evt);
}
});

tabelKonsumen.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {

},
new String [] {
"Kode", "Nama", "Alamat", "Kota", "Telp", "HP"
}
));
jScrollPane1.setViewportView(tabelKonsumen);

BtnTambah.setText("Tambah");
BtnTambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnTambahActionPerformed(evt);
}
});

BtnKoreksi.setText("Koreksi");
BtnKoreksi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnKoreksiActionPerformed(evt);
}
});

BtnHapus.setText("Hapus");
BtnHapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnHapusActionPerformed(evt);
}
});

BtnSimpan.setText("Simpan");
BtnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnSimpanActionPerformed(evt);
}
});

BtnBatal.setText("Batal");
BtnBatal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnBatalActionPerformed(evt);
}
});

BtnKeluar.setText("Keluar");
BtnKeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnKeluarActionPerformed(evt);
}
});

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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(mKodeKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(mAlamatKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addGap(21, 21, 21)
.addComponent(mKotaKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(128, 128, 128))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(mHPKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addGap(21, 21, 21)
.addComponent(mTelpKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(96, 96, 96))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(mNamaKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGap(146, 146, 146)
.addComponent(BtnTambah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnKoreksi)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnHapus)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnBatal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnKeluar)
.addContainerGap(64, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(mKodeKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(mNamaKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(mAlamatKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(9, 9, 9)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(mKotaKonsumen, 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(jLabel5)
.addComponent(mTelpKonsumen, 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(jLabel6)
.addComponent(mHPKonsumen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BtnTambah)
.addComponent(BtnKoreksi)
.addComponent(BtnHapus)
.addComponent(BtnSimpan)
.addComponent(BtnBatal)
.addComponent(BtnKeluar))
.addContainerGap())
);

pack();
}// </editor-fold>

private void mKodeKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void mNamaKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void mAlamatKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void mKotaKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void mTelpKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void mHPKonsumenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void BtnBatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (pil==3){
BtnSimpan.setText("Simpan");
}
pil = 5;
setTombol(true, true, true, false, false, true);
setEdit(false, false, false, false, false, false);
bersih();
BtnTambah.requestFocus();
}

private void BtnTambahActionPerformed(java.awt.event.ActionEvent evt) {
pil = 1;
setTombol(false, false, false, false, true, false);
setEdit(true, false, false, false, false, false);
jLabel1.requestFocus();
}

private void BtnKoreksiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pil = 2;
setTombol(false, false, false, false, true, false);
setEdit(true, false, false, false, false, false);
jLabel1.requestFocus();
}

private void BtnHapusActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
pil = 2;
setTombol(false, false, false, false, true, false);
setEdit(true, false, false, false, false, false);
jLabel1.requestFocus();
}

private void BtnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (pil==1){
simpanData();
} else if (pil==2){
koreksiData();
}
tampilTabel();
pil = 4;
setTombol(true, true, true, false, false, true);
setEdit(false, false, false, false, false, false);
bersih();
BtnTambah.requestFocus();
}

private void BtnKeluarActionPerformed(java.awt.event.ActionEvent 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(FrmKonsumen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FrmKonsumen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FrmKonsumen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FrmKonsumen.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 FrmKonsumen().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton BtnBatal;
private javax.swing.JButton BtnHapus;
private javax.swing.JButton BtnKeluar;
private javax.swing.JButton BtnKoreksi;
private javax.swing.JButton BtnSimpan;
private javax.swing.JButton BtnTambah;
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.JScrollPane jScrollPane1;
private javax.swing.JTextField mAlamatKonsumen;
private javax.swing.JTextField mHPKonsumen;
private javax.swing.JTextField mKodeKonsumen;
private javax.swing.JTextField mKotaKonsumen;
private javax.swing.JTextField mNamaKonsumen;
private javax.swing.JTextField mTelpKonsumen;
private javax.swing.JTable tabelKonsumen;
// End of variables declaration
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.