Assalamualaikum Wr.Wb
Oke guys kali ini saya akan kasih contoh menggunakan netbeans IDE 8.2
untuk UTS Algoritma Pemrograman II.
Program ini di fungsikan untuk menghitung jumlah tagihan untuk konsumen atau pelanggan.
Cara kerja penggunaan program ini cukup mudah dipahami, karena tidak memiliki banyak menu pada jendela program. Berikut cara penggunaan program :
- Jalankan Program , Isi Nama dan No Identitas ( KTP / SIM / Passport )
- Isi tanggal lahir
- Pilih jenis tiket yang anda inginkan
- Masukan jumlah tiket yang anda inginkan lalu klik total dan aplikasi akan memprose
- Jika anda ingin menghapus data silahkan pilih clear dan jika anda ingin menutup aplikasi pilih exit
setelah mengetahui cara kerja program, saya akan menjelaskan secara singkat cara membuat program tersebut. yang hasilnya akan seperti ini :
Langkah pertama buka Aplikasi "Netbeans IDE" pilih New Project => Java Application lalu klik Next, Isi Project Name nya lalu klik Finish.
Setelah itu akan muncul fram form untuk desain output program nya, lalu selanjutnya siapkan :
- combo box
- JLabel
- Textfield
- radio button
- check box
Lalu Creat Design seperti gambar dibawah ini :
Untuk Melihat Codingannya berada disini :
Flowcart :
Untuk coding lengkap nya bisa di liat disini :
/*
* 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 javaapplication;
/**
*
* @author L
*/
public class TiketKonser extends javax.swing.JFrame {
/**
* Creates new form TiketKonser
*/
public TiketKonser() {
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() {
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
TxtNama = new javax.swing.JTextField();
TxtId = new javax.swing.JTextField();
TxtHarga = new javax.swing.JTextField();
TxtJumlah = new javax.swing.JTextField();
TxtTotal = new javax.swing.JTextField();
Jtgl = new javax.swing.JComboBox<>();
Jbln = new javax.swing.JComboBox<>();
Jthn = new javax.swing.JComboBox<>();
VVIP = new javax.swing.JRadioButton();
VIP = new javax.swing.JRadioButton();
SIL = new javax.swing.JRadioButton();
ButTotal = new javax.swing.JButton();
ButExit = new javax.swing.JButton();
ButClear = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel3.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 18)); // NOI18N
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("PEMESANAN TIKET KONSER Ed Sheeran");
jLabel4.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel4.setText("No Identitas ( KTP / SIM / Passport )");
jLabel5.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel5.setText("Nama");
jLabel6.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel6.setText("Harga Tiket");
jLabel7.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel7.setText("Tanggal Lahir");
jLabel8.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel8.setText("Jenis Tiket");
jLabel9.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel9.setText("Jumlah Tiket");
jLabel10.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
jLabel10.setText("Total Harga Tiket");
TxtNama.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
TxtNama.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TxtNamaActionPerformed(evt);
}
});
TxtId.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
TxtId.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TxtIdActionPerformed(evt);
}
});
TxtHarga.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
TxtHarga.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TxtHargaActionPerformed(evt);
}
});
TxtJumlah.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
TxtJumlah.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TxtJumlahActionPerformed(evt);
}
});
TxtTotal.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
TxtTotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TxtTotalActionPerformed(evt);
}
});
Jtgl.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
Jtgl.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
Jbln.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
Jbln.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
Jbln.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
JblnActionPerformed(evt);
}
});
Jthn.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
Jthn.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001" }));
VVIP.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
VVIP.setText("VVIP");
VVIP.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
VVIPActionPerformed(evt);
}
});
VIP.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
VIP.setText("VIP");
VIP.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
VIPActionPerformed(evt);
}
});
SIL.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
SIL.setText("Silver");
SIL.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SILActionPerformed(evt);
}
});
ButTotal.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
ButTotal.setText("Total");
ButTotal.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButTotalActionPerformed(evt);
}
});
ButExit.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
ButExit.setText("Exit");
ButExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButExitActionPerformed(evt);
}
});
ButClear.setFont(new java.awt.Font("Lucida Sans Typewriter", 1, 11)); // NOI18N
ButClear.setText("Clear");
ButClear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ButClearActionPerformed(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()
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(26, 26, 26))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(TxtNama, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(ButTotal)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ButClear)
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(ButExit))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel8)
.addComponent(jLabel7))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Jtgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Jbln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Jthn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(TxtId, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(VVIP, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(VIP, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(SIL, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel6)
.addComponent(jLabel10))
.addGap(144, 144, 144)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(TxtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtNama, javax.swing.GroupLayout.DEFAULT_SIZE, 26, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtId))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Jtgl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jbln, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jthn, 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.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(VVIP)
.addComponent(VIP)
.addComponent(SIL))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtJumlah))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(TxtTotal))
.addGap(14, 14, 14)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(ButTotal)
.addComponent(ButClear))
.addContainerGap(22, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(ButExit))))
);
pack();
}// </editor-fold>
private void TxtNamaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void TxtIdActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void TxtHargaActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void TxtJumlahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void TxtTotalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ButExitActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void ButTotalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int Jumlah = Integer.parseInt(TxtJumlah.getText());
int Harga = Integer.parseInt(TxtHarga.getText());
int Total = Jumlah*Harga;
TxtTotal.setText("Rp."+Total);
}
private void JblnActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void VVIPActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TxtHarga.setText("3000000");
}
private void VIPActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TxtHarga.setText("2000000");
}
private void SILActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TxtHarga.setText("1000000");
}
private void ButClearActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
TxtNama.setText(null);
TxtId.setText(null);
Jtgl.setSelectedIndex(-1);
Jbln.setSelectedIndex(-1);
Jthn.setSelectedIndex(-1);
VIP.setSelected(false);
VVIP.setSelected(false);
SIL.setSelected(false);
TxtHarga.setText(null);
TxtJumlah.setText(null);
TxtTotal.setText(null);
}
/**
* @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(TiketKonser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TiketKonser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TiketKonser.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TiketKonser.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 TiketKonser().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton ButClear;
private javax.swing.JButton ButExit;
private javax.swing.JButton ButTotal;
private javax.swing.JComboBox<String> Jbln;
private javax.swing.JComboBox<String> Jtgl;
private javax.swing.JComboBox<String> Jthn;
private javax.swing.JRadioButton SIL;
private javax.swing.JTextField TxtHarga;
private javax.swing.JTextField TxtId;
private javax.swing.JTextField TxtJumlah;
private javax.swing.JTextField TxtNama;
private javax.swing.JTextField TxtTotal;
private javax.swing.JRadioButton VIP;
private javax.swing.JRadioButton VVIP;
private javax.swing.JLabel jLabel10;
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;
// End of variables declaration
}
MANTAB BRO
BalasHapus