Assalamu’alaikum wr wb,
Dalam penjelasan projek
kali ini sama dengan yang saya jelaskan dalam tugas kemarin. Yaitu program
penjualan menggunakan JAVA GUI,untuk menjalankannya program ini user hanya
memilih berupa kode barang,kode yang dipilih akan dikalikan dengan jumlah yang
akan dibeli.User juga bisa memilih merk barang dan ukuran sepatu yang akan
dibeli dengan menggunakan combo box.Jika sudah membeli user bisa langsung
keluar dengan memilih button “Keluar” menggunakan Joptionpane.
Contoh Design & Output Run;
Variable :
private javax.swing.JComboBox<String> CmbmerkF;
private
javax.swing.JComboBox<String> Cmbsb;
private
javax.swing.JComboBox<String> Cmbukuranf;
private
javax.swing.JComboBox<String> Cmbukurans;
private javax.swing.JRadioButton
RB1;
private
javax.swing.JRadioButton RB2;
private
javax.swing.JRadioButton RB3;
private
javax.swing.JRadioButton RB4;
private
javax.swing.JRadioButton RB5;
private
javax.swing.JButton btnHapus;
private javax.swing.JButton
btnHitung;
private
javax.swing.JComboBox<String> cmbbs;
private
javax.swing.JComboBox<String> cmbjk;
private
javax.swing.JComboBox<String> cmbjt;
private
javax.swing.JTextField hslHarga;
private
javax.swing.JTextField hslJenis;
private
javax.swing.JButton jKnfr;
private
javax.swing.JLabel jLabel1;
private
javax.swing.JLabel jLabel10;
private
javax.swing.JLabel jLabel13;
private
javax.swing.JLabel jLabel14;
private
javax.swing.JLabel jLabel16;
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.JLabel jLabel7;
private javax.swing.JLabel
jLabel8;
private
javax.swing.JLabel jLabel9;
private
javax.swing.JPanel jPanel1;
private
javax.swing.JTextField totalBayar;
private
javax.swing.JTextField txtHasil;
private javax.swing.JTextField txtJenis;
Contoh SourceCode :
import javax.swing.JOptionPane;
/*
* 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 ASUS-PC
*/
public class TugasUts extends
javax.swing.JFrame {
double jenis, jumlahbarang, tarif;
String nama;
/**
* Creates new form TugasUts
*/
public TugasUts() {
initComponents();
}
private void btnHitungActionPerformed(java.awt.event.ActionEvent
evt) {
jenis = Float.parseFloat(txtJenis.getText());
jumlahbarang = Float.parseFloat(txtHasil.getText());
if (jenis == 1) {
hslJenis.setText("Sepatu
Bola");
hslHarga.setText("Rp. 200000");
} else if (jenis == 2) {
hslJenis.setText("Sepatu Futsal");
hslHarga.setText("Rp. 150000");
} else if (jenis == 3) {
hslJenis.setText("Jersey
Timnas");
hslHarga.setText("Rp. 95000");
} else if (jenis == 4) {
hslJenis.setText("Jersey Klub");
hslHarga.setText("Rp. 75000");
} else if (jenis == 5) {
hslJenis.setText("Bola Sepak");
hslHarga.setText("Rp. 125000");
}
if (jenis == 1) {
tarif = jumlahbarang * 200000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 2) {
tarif = jumlahbarang * 150000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 3) {
tarif = jumlahbarang * 95000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 4) {
tarif = jumlahbarang * 75000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 5) {
tarif = jumlahbarang * 125000;
totalBayar.setText("Rp. " + tarif);
}
}
SourceCode ButtonHapus :
private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {
private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {
txtJenis.setText("");
txtHasil.setText("");
hslJenis.setText("");
hslHarga.setText("");
totalBayar.setText("");
}
SourceCode JOptionePane :
private void
jKnfrActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int p = JOptionPane.showConfirmDialog(null,
"Yakin
keluar","Konfirmasi",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(p == 0){
System.exit(0);
}
}
SourceCode JRadio :
private void
RB1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RB2.setSelected(false);
RB4.setSelected(false);
RB3.setSelected(false);
RB5.setSelected(false);
txtJenis.setText(RB1.getText());
txtJenis.setText("1");
}
private void RB2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RB1.setSelected(false);
RB3.setSelected(false);
RB4.setSelected(false);
RB5.setSelected(false);
txtJenis.setText(RB2.getText());
txtJenis.setText("2");
}
private void RB5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RB2.setSelected(false);
RB4.setSelected(false);
RB3.setSelected(false);
RB1.setSelected(false);
txtJenis.setText(RB5.getText());
txtJenis.setText("5");
}
private void RB3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RB1.setSelected(false);
RB2.setSelected(false);
RB4.setSelected(false);
RB5.setSelected(false);
txtJenis.setText(RB3.getText());
txtJenis.setText("3");
}
private void RB4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
RB1.setSelected(false);
RB2.setSelected(false);
RB3.setSelected(false);
RB5.setSelected(false);
txtJenis.setText(RB4.getText());
txtJenis.setText("4");
}
SourceCode ComboBox:
private void
formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
Cmbsb.addItem(" ");
Cmbsb.addItem("ADIDAS");
Cmbsb.addItem("NIKE");
Cmbsb.addItem("PUMA");
Cmbsb.addItem("SPECS");
for(int x=29;x<=43;x++){
Cmbukurans.addItem(""+x);}
for(int x=29;x<=43;x++){
Cmbukuranf.addItem(""+x);}