Assalamu’alaikum… :)
Disini saya akan berbagi
tentang penerapan Program JAVA menggunakan NetBeans dan sekaligus untuk
memenuhi tugas UTS “ALGORITMA DAN PEMROGRAMAN”.
Contohnya pembuatan form
“Penjualan Laptop” seperti gambar berikut.
Ini adalah gambar Source Codingnya..!
Source Codingnya yaitu:
public class Tryagain
extends javax.swing.JFrame {
/**
* Creates new form Tryagain
*/
public Tryagain() {
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() {
jScrollPane1 = new
javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
buttonGroup1 = new javax.swing.ButtonGroup();
VBrand = new javax.swing.JLabel();
VJumlahbarang = new
javax.swing.JLabel();
VProcessor = new javax.swing.JLabel();
VHarga = new javax.swing.JLabel();
ComboProcessor = new
javax.swing.JComboBox();
ComboBrand = new javax.swing.JComboBox();
Harga1 = new javax.swing.JTextField();
Jumlahbarang1 = new
javax.swing.JTextField();
Proses1 = new javax.swing.JButton();
Selesai1 = new javax.swing.JButton();
Mulai1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
VHasil = new javax.swing.JLabel();
Hasil1 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jList1.setModel(new
javax.swing.AbstractListModel() {
String[] strings = { "Item
1", "Item 2", "Item 3", "Item 4", "Item
5" };
public int getSize() { return
strings.length; }
public Object getElementAt(int i) {
return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new
java.awt.event.WindowAdapter() {
public void
windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
public void
windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
VBrand.setText("Brand");
VJumlahbarang.setText("Jumlah
Barang");
VProcessor.setText("Processor");
VHarga.setText("Harga");
ComboProcessor.setModel(new
javax.swing.DefaultComboBoxModel(new String[] { "Corei3", "Core
2 Duo", "Intel Atom", "AMD" }));
ComboProcessor.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
ComboProcessorActionPerformed(evt);
}
});
ComboBrand.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
ComboBrandActionPerformed(evt);
}
});
Harga1.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
Harga1ActionPerformed(evt);
}
});
Proses1.setText("Proses");
Proses1.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
Proses1ActionPerformed(evt);
}
});
Selesai1.setText("Selesai");
Selesai1.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
Selesai1ActionPerformed(evt);
}
});
Mulai1.setText("Mulai");
Mulai1.addActionListener(new
java.awt.event.ActionListener() {
public void
actionPerformed(java.awt.event.ActionEvent evt) {
Mulai1ActionPerformed(evt);
}
});
jLabel1.setFont(new
java.awt.Font("Curlz MT", 3, 18)); // NOI18N
jLabel1.setForeground(new
java.awt.Color(255, 153, 153));
jLabel1.setText(" PENJUALAN
LAPTOP");
VHasil.setText("Hasil");
jLabel2.setText("Rp.");
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(Proses1,
javax.swing.GroupLayout.PREFERRED_SIZE, 144,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(128, 128, 128))
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(VHasil,
javax.swing.GroupLayout.PREFERRED_SIZE, 107,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52)
.addComponent(Hasil1,
javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(VProcessor, javax.swing.GroupLayout.PREFERRED_SIZE, 107,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52)
.addComponent(ComboProcessor, javax.swing.GroupLayout.PREFERRED_SIZE,
176, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
layout.createSequentialGroup()
.addComponent(VBrand,
javax.swing.GroupLayout.PREFERRED_SIZE, 107,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(52, 52, 52)
.addComponent(ComboBrand,
javax.swing.GroupLayout.PREFERRED_SIZE, 176,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(VJumlahbarang, javax.swing.GroupLayout.PREFERRED_SIZE,
107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(VHarga,
javax.swing.GroupLayout.PREFERRED_SIZE, 107,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(23, 23,
23)
.addComponent(jLabel2)))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Harga1, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jumlahbarang1,
javax.swing.GroupLayout.PREFERRED_SIZE, 176,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 31,
Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(32, 32, 32)
.addComponent(Mulai1,
javax.swing.GroupLayout.PREFERRED_SIZE, 144,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Selesai1,
javax.swing.GroupLayout.PREFERRED_SIZE, 144,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(34, 34, 34))
.addGroup(layout.createSequentialGroup()
.addGap(89, 89, 89)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 199,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE,
44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(VHarga,
javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(111, 111, 111))
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ComboBrand, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(VBrand, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ComboProcessor, javax.swing.GroupLayout.PREFERRED_SIZE,
24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(VProcessor, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addComponent(Harga1,
javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Jumlahbarang1, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(VJumlahbarang, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Hasil1,
javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(VHasil, javax.swing.GroupLayout.PREFERRED_SIZE, 25,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46,
Short.MAX_VALUE)))
.addComponent(Proses1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Selesai1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(Mulai1)
.addGap(41, 41, 41))))
);
pack();
}// </editor-fold>
private void
ComboBrandActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void
formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
ComboBrand.addItem("ACER");
ComboBrand.addItem("ASUS");
ComboBrand.addItem("SAMSUNG");
ComboBrand.addItem("COMPACT");
ComboBrand.addItem("HP");
ComboBrand.addItem("LENOVO");
}
private void
formWindowClosed(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
}
private void ComboProcessorActionPerformed(java.awt.event.ActionEvent
evt) {
// TODO add your handling code here:
if(ComboProcessor.getSelectedItem()=="Corei3"){
Harga1.setText("8000000");
}else if(ComboProcessor.getSelectedItem()=="Core
2 Duo"){
Harga1.setText("7000000");
}else
if(ComboProcessor.getSelectedItem()=="Intel Atom"){
Harga1.setText("6500000");
}else{
Harga1.setText("6000000");
}
}
private void
Mulai1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Harga1.setText("");
Jumlahbarang1.setText("");
Hasil1.setText("");
}
private void
Proses1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int harga=Integer.parseInt(Harga1.getText());
int
jumlah=Integer.parseInt(Jumlahbarang1.getText());
int proses=harga*jumlah;
Hasil1.setText(""+proses);
}
private void
Selesai1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
System.exit(0);
}
private void Harga1ActionPerformed(java.awt.event.ActionEvent
evt) {
// 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(Tryagain.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Tryagain.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Tryagain.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch
(javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Tryagain.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
Tryagain().setVisible(true);
}
});
}
// Variables declaration - do not
modify
private javax.swing.JComboBox ComboBrand;
private javax.swing.JComboBox
ComboProcessor;
private javax.swing.JTextField Hasil1;
private javax.swing.JTextField
Jumlahbarang1;
private javax.swing.JButton Mulai1;
private javax.swing.JButton Proses1;
private javax.swing.JButton Selesai1;
private javax.swing.JLabel VBrand;
private javax.swing.JLabel VHarga;
private javax.swing.JLabel VHasil;
private javax.swing.JLabel VJumlahbarang;
private javax.swing.JLabel VProcessor;
private javax.swing.ButtonGroup
buttonGroup1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JList jList1;
private javax.swing.JScrollPane
jScrollPane1;
// End of variables declaration
}
Selesai…
semoga nilai UTS nya memuaskan, aamiin..
Wassalamu’alaikum.. :)
Tidak ada komentar:
Posting Komentar