Untuk pertama kalinya nih Admin share tutorial. Kali ini Admin akan membagikan tutorial membuat Aplikasi Laundry berbasis java, bisa menggunakan BlueJ ataupun Netbeans.
Berikut kodenya:
import javax.swing.JOptionPane;
public class MainLaundry extends javax.swing.JFrame {
public int total =0;
public MainLaundry() {
initComponents();
SetEnabledFalse();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
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();
txtNama = new javax.swing.JTextField();
txtNoHp = new javax.swing.JTextField();
txtTotal = new javax.swing.JTextField();
txtAlamat = new javax.swing.JTextField();
CbPakaian = new javax.swing.JCheckBox();
CbSelimut = new javax.swing.JCheckBox();
CbTas = new javax.swing.JCheckBox();
jScrollPane1 = new javax.swing.JScrollPane();
txtHasil = new javax.swing.JTextArea();
BtnTambah = new javax.swing.JButton();
BtnSimpan = new javax.swing.JButton();
BtnKembali = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(0, 102, 102));
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("APLIKASI LAUNDRY");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(37, 37, 37)
.addComponent(jLabel1)
.addContainerGap(30, Short.MAX_VALUE))
);
jLabel2.setText("Nama");
jLabel3.setText("Jenis");
jLabel4.setText("Alamat");
jLabel5.setText("No Hp");
jLabel6.setText("Total Bayar");
txtTotal.setEditable(false);
txtTotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtTotalActionPerformed(evt);
}
});
CbPakaian.setText("Pakaian");
CbPakaian.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CbPakaianActionPerformed(evt);
}
});
CbSelimut.setText("Selimut");
CbSelimut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CbSelimutActionPerformed(evt);
}
});
CbTas.setText("Tas");
CbTas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
CbTasActionPerformed(evt);
}
});
txtHasil.setEditable(false);
txtHasil.setColumns(20);
txtHasil.setRows(5);
jScrollPane1.setViewportView(txtHasil);
BtnTambah.setText("Tambah");
BtnTambah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnTambahActionPerformed(evt);
}
});
BtnSimpan.setText("Simpan");
BtnSimpan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnSimpanActionPerformed(evt);
}
});
BtnKembali.setText("Kembali");
BtnKembali.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnKembaliActionPerformed(evt);
}
});
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.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(jLabel3))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(62, 62, 62)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(CbPakaian)
.addComponent(CbSelimut, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(CbTas, javax.swing.GroupLayout.Alignment.LEADING)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(BtnTambah)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnSimpan)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(BtnKembali))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel5)
.addComponent(jLabel6))
.addGap(34, 34, 34)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtNoHp, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.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.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1)
.addGap(52, 52, 52))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(txtNama, 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(jLabel3)
.addComponent(CbPakaian))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CbSelimut)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(CbTas)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel4))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtNoHp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(BtnKembali)
.addComponent(BtnSimpan)
.addComponent(BtnTambah))
.addGap(0, 39, Short.MAX_VALUE))))
);
pack();
}
private void CbPakaianActionPerformed(java.awt.event.ActionEvent evt) {
if(CbPakaian.isSelected()){
total = total + 6000; //Untuk Menambahkan Harga
}else{
total = total - 6000;
}
txtTotal.setText(String.valueOf(total));
}
private void txtTotalActionPerformed(java.awt.event.ActionEvent evt) {
}
private void CbSelimutActionPerformed(java.awt.event.ActionEvent evt) {
if(CbSelimut.isSelected()){
total = total + 20000; //Untuk Menambahkan Harga
}else{
total = total - 20000;
}
txtTotal.setText(String.valueOf(total));
}
private void CbTasActionPerformed(java.awt.event.ActionEvent evt) {
if(CbTas.isSelected()){
total = total + 10000; //Untuk Menambahkan Harga
}else{
total = total - 10000;
}
txtTotal.setText(String.valueOf(total));
}
private void BtnSimpanActionPerformed(java.awt.event.ActionEvent evt) {
if((txtNama.getText().length()!=0)&&(txtAlamat.getText().length()!=0)&&(txtNoHp.getText().length()!=0)&&(txtTotal.getText().length()!=0 )&& (CbPakaian.getText().length()!=0) && (CbSelimut.getText().length()!=0)&&(CbTas.getText().length()!=0 )){
txtHasil.append("Nama : " +txtNama.getText()+
"nAlamat : " +txtAlamat.getText()+
"nNo Handphone : " +txtNoHp.getText() +
"nTotal Harga : " +String.valueOf(total)+
"nPesanan Anda adalah : ");
if(CbPakaian.isSelected()){
txtHasil.append("n-Pakaiann");
}
if(CbSelimut.isSelected()){
txtHasil.append("-Selimutn");
}
if(CbTas.isSelected()){
txtHasil.append("-Tasn");
}
}else{
JOptionPane.showMessageDialog(this, "Masukan Data Dengan Benar");
}
}
private void BtnTambahActionPerformed(java.awt.event.ActionEvent evt) {
SetEnabledTrue();
}
private void BtnKembaliActionPerformed(java.awt.event.ActionEvent evt) {
SetEnabledFalse();
}
public void SetEnabledTrue(){
txtNama.setEnabled(true);
txtAlamat.setEnabled(true);
txtNoHp.setEnabled(true);
txtTotal.setEnabled(true);
CbPakaian.setEnabled(true);
CbSelimut.setEnabled(true);
CbTas.setEnabled(true);
}
public void SetEnabledFalse(){
txtNama.setEnabled(false);
txtAlamat.setEnabled(false);
txtNoHp.setEnabled(false);
txtTotal.setEnabled(false);
CbPakaian.setEnabled(false);
CbSelimut.setEnabled(false);
CbTas.setEnabled(false);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
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(MainLaundry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainLaundry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainLaundry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainLaundry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainLaundry().setVisible(true);
}
});
}
private javax.swing.JButton BtnKembali;
private javax.swing.JButton BtnSimpan;
private javax.swing.JButton BtnTambah;
private javax.swing.JCheckBox CbPakaian;
private javax.swing.JCheckBox CbSelimut;
private javax.swing.JCheckBox CbTas;
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.JScrollPane jScrollPane1;
private javax.swing.JTextField txtAlamat;
private javax.swing.JTextArea txtHasil;
private javax.swing.JTextField txtNama;
private javax.swing.JTextField txtNoHp;
private javax.swing.JTextField txtTotal;
}
Berikut hasilnya:
Saat pertama kali di Run
Saat meng-klik button/tombol Tambah
Aplikasi Laundry |
Aplikasi Laundry |
Sekian tutorial dari saya, semoga bermanfaat. Silahkan di kembangkan lagi agar lebih menarik tentunya..
0 Comments
Post a Comment
Silahkan tinggalkan komentar jika Anda punya saran, kritik, atau pertanyaan seputar topik pembahasan. Gunakan bahasa yang bijak dan santun. Terima Kasih.