Ini Source Code nya: public class penjualan extends javax.swing.JFrame { double jenis, barang, tarif; /** * Creates new form penjualan */ public penjualan() { 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") //
Senin, 24 April 2017
Program Penjualan java GUI
Assalamu’alaikum wr wb,
Dalam penjelasan projek kali ini sama dengan yang saya jelaskan dalam uts 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.
Pembahasan :
Untuk pengggunaa variablenya ,saya hanya menggunakan satu tipe variable yaitu double lalu ada beberapa method yaitu :
jenis,untuk menyimpan jenis barang .
barang,untuk menyimpan harga barang .
tarif, untuk menyimpan total bayar.
Ini screen shotnya:
Ini Source Code nya: public class penjualan extends javax.swing.JFrame { double jenis, barang, tarif; /** * Creates new form penjualan */ public penjualan() { 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") //
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel2 = new javax.swing.JLabel();
RB1 = new javax.swing.JRadioButton();
RB2 = new javax.swing.JRadioButton();
RB3 = new javax.swing.JRadioButton();
RB4 = new javax.swing.JRadioButton();
jLabel3 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
totalBayar = new javax.swing.JTextField();
bh = new javax.swing.JButton();
txtJenis = new javax.swing.JTextField();
txtHasil = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
RB5 = new javax.swing.JRadioButton();
btnHapus = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Toko OlahRaga WAW");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setText("\tHarga Barang\n1.Sepatu Bola \tRp.200.000\n2.Sepatu Futsal Rp.150.000\n3.Jersey Timnas Rp.95.000\n4.Jersey Klub \tRp.75.000\n5.Bola Sepak\tRp.125000\n");
jScrollPane1.setViewportView(jTextArea1);
jLabel2.setText("Daftar Barang:");
RB1.setText("1.Sepatu Bola");
RB1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RB1ActionPerformed(evt);
}
});
RB2.setText("2.Sepatu Futsal");
RB2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RB2ActionPerformed(evt);
}
});
RB3.setText("3.Jersey Timnas");
RB3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RB3ActionPerformed(evt);
}
});
RB4.setText("4.Jersey klub");
RB4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RB4ActionPerformed(evt);
}
});
jLabel6.setText("Total Bayar:");
totalBayar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
totalBayarActionPerformed(evt);
}
});
bh.setText("Hitung");
bh.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bhActionPerformed(evt);
}
});
txtJenis.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtJenisActionPerformed(evt);
}
});
jLabel7.setText("Kode Barang:");
jLabel8.setText("Jumlah :");
RB5.setText("5.Bola Sepak");
RB5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RB5ActionPerformed(evt);
}
});
btnHapus.setText("Hapus");
btnHapus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnHapusActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(266, 266, 266))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(RB3)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(RB1)
.addComponent(RB2))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(RB5)
.addComponent(RB4)))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(13, 13, 13))
.addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(bh)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnHapus))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(totalBayar)
.addComponent(txtJenis, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
.addComponent(txtHasil, javax.swing.GroupLayout.Alignment.TRAILING)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 6, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(81, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(22, 22, 22)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RB1)
.addComponent(RB4)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RB2)
.addComponent(RB5))
.addGap(10, 10, 10)
.addComponent(RB3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtJenis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtHasil, 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(totalBayar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(bh)
.addComponent(btnHapus))
.addGap(172, 172, 172))))
);
pack();
}//
private void txtJenisActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void bhActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
jenis = Float.parseFloat(txtJenis.getText());
barang = Float.parseFloat(txtHasil.getText());
if (jenis == 1) {
tarif = barang * 200000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 2) {
tarif = barang * 150000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 3) {
tarif = barang * 95000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 4) {
tarif = barang * 75000;
totalBayar.setText("Rp. " + tarif);
} else if (jenis == 5) {
tarif = barang * 125000;
totalBayar.setText("Rp. " + tarif);
}
}
private void totalBayarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
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");
}
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 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 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 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 btnHapusActionPerformed(java.awt.event.ActionEvent evt) {
txtJenis.setText("");
txtHasil.setText("");
totalBayar.setText("");
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//
/* 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(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(penjualan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new penjualan().setVisible(true);
}
});
}
// Variables declaration - do not modify
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 bh;
private javax.swing.JButton btnHapus;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField totalBayar;
private javax.swing.JTextField txtHasil;
private javax.swing.JTextField txtJenis;
// End of variables declaration
}
Ini Source Code nya: public class penjualan extends javax.swing.JFrame { double jenis, barang, tarif; /** * Creates new form penjualan */ public penjualan() { 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") //
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar