Assalamualaikum Wr. Wb.
Hai teman-teman, perkenalkan saya Bimo Wicaksono, saya berkuliah di STMIK ERESHA, dan pada kesempatan kali ini, saya akan memberikan teman-teman sebuah tutorial, tentang bagaimana membuat program sederhana menggunakan Netbeans 8.2 . Dan sebenarnya sekaligus ini adalah tugas UTS saya di semester 5 ini hehehe..
1. Deskripsi Project
Di zaman saat ini sangat pengting sekali Aplikasi tiketing Online, baik tiket untuk naik pesawat, kereta, kapal, bis, bahkan saat ini kita pun dapat membeli tiket biskop atau tiket konser secara online. Salah satu contoh program yang saya buat kali ini adalah tentang bagaimana cara membuat aplikasi pembelian tiket Online secara sederhana. Bagi kalian yang sering sekali bepergian menggunakan kereta api, aplikasi semacam ini pastinya akan sangat membatu kalian dalam pemesanan tiket.
2. Flowchart
Adapun Flowchart atau alur dari program ini adalah sebagai berikut :
Apabila Flowchart ini kurang dipahami bisa kalian tuliskan di kolom komentar yaa guys.
3. Screenshot Program/Aplikasi
Dibawah ini adalah tampilan awal saat program/Aplikasi dijalankan. Kalo tampilannya kurang menarik mohon maaf yaa, lagi males desain soalnya hehehe. Bisa dilihat bahwa pada Panel Biru itu adalah pemilihan kereta LRT-nya dan pada Panel Kuning(agak cream) itu adalah tempat pengisian data penumpang, jumlah tiket yang ingin kita pesan dan total yang harus dibayarkan nanti ketika sudah mendapatkan kode pembayaran melalui pesan/sms/email(anggap aja sebelum daftar program ini kalian harus masukin email hehehe)
Kemudian kita pilih tujuan yang kita inginkan. Untuk tujuan pilihan, dan ada pilihan apa saja kalian bisa simak pada gambar di bawah ini.
Nahh, sekaeang anggap saja kita memilih pilihan rute "Tangerang - Jakarta Pusat". Dan sekarang kita tinggal memilih mau yang kelas ekonomi atau kelas eksekutif. Karena terdapat perbedaan harga di kelas/jenis kerena ekonomi atau eksekutif. Liat dehh di bawah kalo ngga percaya hehehe
Tuhh, bedakan?? Dan harganya juga beda, baik yang ekonomi atau yang eksekutif. Biar keliatan keren kita akan naik yang eksekutif. Mantapp!! Maap yaa kalo harga- harga tiketnya dibikin kemahalan, namanya juga contoh, aslinya mahh dijamin murah kok. Sekarang kira tinggal pilih tanggal, bulan, dan tahun kebarangkatan yang kita inginkan. Misal kita mau berangkat tanggal 29 Oktober 2019.
Nahhh, kalau sudah kita setting tanggal keberangkatan yang kita inginkan, sekarang kita masukan nama kita. karena ini program/aplikasi bikinin saya sendiri, jadi yaa harus saya coba nama saya lahh hehehe.
Sekarang kita masukin berapa jumlah tiket yang ingin kita pesan. Karena ini kereta jadi bisa diwakilin dan kali ini saya akan beli 2 tiket untuk saya dan pasangan saya. Kalo yang jomblo 1 aja yaa beli tiketnya, ehh lebih juga boleh dehh hehehe.
Liat dahh tuh gambar diatas saat kita masukan jumlah tiket yang kita ingin beli, maka secara otomatis total harga tiket sudah terhitung. Sekarang tinggal kita pilih mau pesan, cancel (lahh basaha inggris sendiri ini), keluar. Sekarang anggap aja kita pesan dulu yaa.
Tuhh, muncul tulisan apa tuhh barusan kalo kita klik "pesan". Sekarang kita coba bagaimana kalau di klik "cancel".
Ilang semua kan data yang tadi kita tulis kalo kita klik "cancel". Ini sihh, sebenernya yaa sama aja kaya reset gitu, cuma namanya ada gw ganti jadi cancel wkwkwk. Karena sudah kehapus semua yaudah kita klik "keluar" biar ditutup program/aplikasinya. Kalo keluar ngga usah saya kasih gambar yaa, soalnya langsung keluar gitu aja, ngga ada pilihan kaya program lain gitu ada tulisan "Apakah anda yakin ingin keluar?". Biar cepet, jadi ngga usah ditanya kaya gitu.
4. Souce Code
Ini nihh yang sebenernya paling dicari, yaitu source codenya. Tapi percuma, sebenernya ngga bisa di Copas(Copy Paste), karena kan kalian harus buat framenya dulu. Soalnya ini pake kaya combo box, text field, dan kawan-kawannya gitu dehh hehehe. Tapi kalo untuk belajar, dan cari referensi yaa monggo aja. Di bawah ini yaa friend source codenya :
/*
* 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 semester_5.UTS;
import javax.swing.JOptionPane;
/**
*
* @author Bimsss
*/
public class TiketKereta extends javax.swing.JFrame {
int nama, jumlah, ekonomi, eksekutif, harga, total, tanggal;
/**
* Creates new form TiketKereta
*/
public TiketKereta() {
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() {
btngjnskereta = new javax.swing.ButtonGroup();
btngkeluar = new javax.swing.ButtonGroup();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
pnlprint = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
Listtujuancmb = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
RBeksekutif = new javax.swing.JRadioButton();
RBekonomi = new javax.swing.JRadioButton();
jLabel8 = new javax.swing.JLabel();
blncmb = new javax.swing.JComboBox<>();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
txfhargatiket = new javax.swing.JTextField();
tglcmb = new javax.swing.JComboBox<>();
tahuncmb = new javax.swing.JComboBox<>();
jPanel2 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
txfnama = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txftotal = new javax.swing.JTextField();
txfjmltiket = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
btnreset = new javax.swing.JButton();
btncetak = new javax.swing.JButton();
btnkeluar = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jTextField2.setText("jTextField2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 204, 204));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jLabel1.setFont(new java.awt.Font("Pristina", 1, 25)); // NOI18N
jLabel1.setText("Pesan Tiket Online LRT Antar Kota");
pnlprint.setBackground(new java.awt.Color(153, 153, 255));
jLabel2.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel2.setText("Pilih Destinasi Tujuan");
Listtujuancmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
Listtujuancmb.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "----- Pilih Tujuan -----", "Tangerang - Bekasi", "Tangerang - Bogor", "Tangerang - Depok", "Tangerang - Jakarta Barat", "Tangerang - Jakarta Pusat", "Tangerang - Jakarta Selatan", "Tangerang - Jakarta Timur", "Tangerang - Jakarta Utara" }));
Listtujuancmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ListtujuancmbActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel3.setText("Jenis Kereta");
btngjnskereta.add(RBeksekutif);
RBeksekutif.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
RBeksekutif.setText("Eksekutif");
RBeksekutif.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RBeksekutifActionPerformed(evt);
}
});
btngjnskereta.add(RBekonomi);
RBekonomi.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
RBekonomi.setText("Ekonomi");
RBekonomi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RBekonomiActionPerformed(evt);
}
});
jLabel8.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel8.setText("Pilih Tanggal Keberangkatan");
blncmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
blncmb.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Bulan", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" }));
blncmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
blncmbActionPerformed(evt);
}
});
jLabel11.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel11.setText("Harga/tiket");
jLabel12.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel12.setText("Rp.");
txfhargatiket.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tglcmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tahuncmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tahuncmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tahuncmbActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlprintLayout = new javax.swing.GroupLayout(pnlprint);
pnlprint.setLayout(pnlprintLayout);
pnlprintLayout.setHorizontalGroup(
pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlprintLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlprintLayout.createSequentialGroup()
.addComponent(tglcmb, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(blncmb, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tahuncmb, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlprintLayout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txfhargatiket))
.addGroup(pnlprintLayout.createSequentialGroup()
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addGroup(pnlprintLayout.createSequentialGroup()
.addComponent(RBekonomi)
.addGap(28, 28, 28)
.addComponent(RBeksekutif))
.addComponent(jLabel8)
.addComponent(jLabel3))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(Listtujuancmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pnlprintLayout.setVerticalGroup(
pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlprintLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Listtujuancmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RBekonomi)
.addComponent(RBeksekutif))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(txfhargatiket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(blncmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tglcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tahuncmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(218, 218, 218))
);
jPanel2.setBackground(new java.awt.Color(255, 255, 102));
jLabel4.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel4.setText("Nama Lengkap");
txfnama.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel5.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel5.setText("Jumlah Tiket");
jLabel6.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel6.setText("Total");
txftotal.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txfjmltiket.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txfjmltiket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txfjmltiketActionPerformed(evt);
}
});
txfjmltiket.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txfjmltiketKeyReleased(evt);
}
});
jLabel10.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel10.setText("Tiket");
btnreset.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btnreset.setText("Cancel");
btnreset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnresetActionPerformed(evt);
}
});
btncetak.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btncetak.setText("Pesan");
btncetak.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btncetakActionPerformed(evt);
}
});
btnkeluar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
jLabel7.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel7.setText("Rp.");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel5))
.addGap(10, 10, 10)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txfnama)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(txfjmltiket, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel10)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txftotal, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btnreset, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnkeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(6, 6, 6))))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btncetak, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txfnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txfjmltiket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(txftotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btncetak)
.addComponent(btnreset)
.addComponent(btnkeluar))
.addContainerGap(45, Short.MAX_VALUE))
);
jLabel15.setFont(new java.awt.Font("Pristina", 1, 20)); // NOI18N
jLabel15.setText("Via Kota Tangerang");
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()
.addGap(0, 35, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlprint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(34, 34, 34))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel15)
.addGap(127, 127, 127))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlprint, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(29, 29, 29))
);
pack();
}// </editor-fold>
private void RBekonomiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Menampilkan harga tiket setelah pilih jenis kereta ekonomi
if(RBekonomi.isSelected()){
txfhargatiket.setText(String.valueOf(ekonomi));
RBeksekutif.setSelected(false);
}
}
private void RBeksekutifActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Menampilkan harga tiket setelah pilih jenis kereta eksekutif
if(RBeksekutif.isSelected()){
txfhargatiket.setText(String.valueOf(eksekutif));
RBekonomi.setSelected(false);
}
}
private void ListtujuancmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//kondisi untuk menetukan harga sesuai pilihan
if(Listtujuancmb.getSelectedItem().equals("----- Pilih Tujuan -----")){
btngjnskereta.clearSelection();
txfhargatiket.setText("");
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Bekasi")){
ekonomi=43000;
eksekutif=53000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Bogor")){
ekonomi=50000;
eksekutif=60000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Depok")){
ekonomi=40000;
eksekutif=55000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Barat")){
ekonomi=15000;
eksekutif=25000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Pusat")){
ekonomi=25000;
eksekutif=40000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Selatan")){
ekonomi=20000;
eksekutif=35000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Timur")){
ekonomi=30000;
eksekutif=45000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Utara")){
ekonomi=20000;
eksekutif=35000;
}
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
int i;
for(i=1;i<=31;i++){
tglcmb.addItem(""+i);
}
int k;
for(k=2019;k<=2100;k++)
{
tahuncmb.addItem(""+k);
}
}
private void blncmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void tahuncmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Untuk membuat tombol keluar berfungsi
this.dispose();
}
private void btncetakActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Fungsi Code ini untuk mengaktifkan fungsi tombol pesan
JOptionPane.showMessageDialog(this, "Terima Kasih. Permintaan anda sedang diproses"
+ "\n Silahkan menunggu email atau pesan kode"
+ "\n pembayaran dari kami.");
}
private void btnresetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Untuk pengeksekusian atau membuat tombol reset/cancel berfungsi
Listtujuancmb.setSelectedItem("----- Pilih Tujuan -----");
RBekonomi.isSelected();
RBeksekutif.isSelected();
txfhargatiket.setText("");
tglcmb.setSelectedItem("1");
blncmb.setSelectedItem("Bulan");
tahuncmb.setSelectedItem("2019");
txfnama.setText("");
txfjmltiket.setText("");
txftotal.setText("");
}
private void txfjmltiketKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
// Ini adalah pendeklarasian rumus dari pembelian tiket
int a, b, c;
a=Integer.valueOf(txfjmltiket.getText());
b=Integer.valueOf(txfhargatiket.getText());
c=a*b;
txftotal.setText(""+c);
}
private void txfjmltiketActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Saat kita menginput jumlah tiket, maka secara otomatis kita akan mengetahui harga tiket dan total harga tiket
jumlah=Integer.parseInt(txfjmltiket.getText());
harga=Integer.parseInt(txfhargatiket.getText());
total=jumlah*harga;
txftotal.setText(String.valueOf(total));
}
/**
* @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(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TiketKereta.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 TiketKereta().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox<String> Listtujuancmb;
private javax.swing.JRadioButton RBekonomi;
private javax.swing.JRadioButton RBeksekutif;
private javax.swing.JComboBox<String> blncmb;
private javax.swing.JButton btncetak;
private javax.swing.ButtonGroup btngjnskereta;
private javax.swing.ButtonGroup btngkeluar;
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnreset;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel15;
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.JPanel jPanel2;
private javax.swing.JTextField jTextField2;
private javax.swing.JPanel pnlprint;
private javax.swing.JComboBox<String> tahuncmb;
private javax.swing.JComboBox<String> tglcmb;
private javax.swing.JTextField txfhargatiket;
private javax.swing.JTextField txfjmltiket;
private javax.swing.JTextField txfnama;
private javax.swing.JTextField txftotal;
// End of variables declaration
}
Terima kasih sudah berkunjung ke blog saya, semoga saya buat artikel lagi bulan depan. :)
Apabila Flowchart ini kurang dipahami bisa kalian tuliskan di kolom komentar yaa guys.
3. Screenshot Program/Aplikasi
Dibawah ini adalah tampilan awal saat program/Aplikasi dijalankan. Kalo tampilannya kurang menarik mohon maaf yaa, lagi males desain soalnya hehehe. Bisa dilihat bahwa pada Panel Biru itu adalah pemilihan kereta LRT-nya dan pada Panel Kuning(agak cream) itu adalah tempat pengisian data penumpang, jumlah tiket yang ingin kita pesan dan total yang harus dibayarkan nanti ketika sudah mendapatkan kode pembayaran melalui pesan/sms/email(anggap aja sebelum daftar program ini kalian harus masukin email hehehe)
Kemudian kita pilih tujuan yang kita inginkan. Untuk tujuan pilihan, dan ada pilihan apa saja kalian bisa simak pada gambar di bawah ini.
Nahh, sekaeang anggap saja kita memilih pilihan rute "Tangerang - Jakarta Pusat". Dan sekarang kita tinggal memilih mau yang kelas ekonomi atau kelas eksekutif. Karena terdapat perbedaan harga di kelas/jenis kerena ekonomi atau eksekutif. Liat dehh di bawah kalo ngga percaya hehehe
Tuhh, bedakan?? Dan harganya juga beda, baik yang ekonomi atau yang eksekutif. Biar keliatan keren kita akan naik yang eksekutif. Mantapp!! Maap yaa kalo harga- harga tiketnya dibikin kemahalan, namanya juga contoh, aslinya mahh dijamin murah kok. Sekarang kira tinggal pilih tanggal, bulan, dan tahun kebarangkatan yang kita inginkan. Misal kita mau berangkat tanggal 29 Oktober 2019.
Sekarang kita masukin berapa jumlah tiket yang ingin kita pesan. Karena ini kereta jadi bisa diwakilin dan kali ini saya akan beli 2 tiket untuk saya dan pasangan saya. Kalo yang jomblo 1 aja yaa beli tiketnya, ehh lebih juga boleh dehh hehehe.
Liat dahh tuh gambar diatas saat kita masukan jumlah tiket yang kita ingin beli, maka secara otomatis total harga tiket sudah terhitung. Sekarang tinggal kita pilih mau pesan, cancel (lahh basaha inggris sendiri ini), keluar. Sekarang anggap aja kita pesan dulu yaa.
Tuhh, muncul tulisan apa tuhh barusan kalo kita klik "pesan". Sekarang kita coba bagaimana kalau di klik "cancel".
Ilang semua kan data yang tadi kita tulis kalo kita klik "cancel". Ini sihh, sebenernya yaa sama aja kaya reset gitu, cuma namanya ada gw ganti jadi cancel wkwkwk. Karena sudah kehapus semua yaudah kita klik "keluar" biar ditutup program/aplikasinya. Kalo keluar ngga usah saya kasih gambar yaa, soalnya langsung keluar gitu aja, ngga ada pilihan kaya program lain gitu ada tulisan "Apakah anda yakin ingin keluar?". Biar cepet, jadi ngga usah ditanya kaya gitu.
4. Souce Code
Ini nihh yang sebenernya paling dicari, yaitu source codenya. Tapi percuma, sebenernya ngga bisa di Copas(Copy Paste), karena kan kalian harus buat framenya dulu. Soalnya ini pake kaya combo box, text field, dan kawan-kawannya gitu dehh hehehe. Tapi kalo untuk belajar, dan cari referensi yaa monggo aja. Di bawah ini yaa friend source codenya :
/*
* 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 semester_5.UTS;
import javax.swing.JOptionPane;
/**
*
* @author Bimsss
*/
public class TiketKereta extends javax.swing.JFrame {
int nama, jumlah, ekonomi, eksekutif, harga, total, tanggal;
/**
* Creates new form TiketKereta
*/
public TiketKereta() {
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() {
btngjnskereta = new javax.swing.ButtonGroup();
btngkeluar = new javax.swing.ButtonGroup();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
pnlprint = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
Listtujuancmb = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
RBeksekutif = new javax.swing.JRadioButton();
RBekonomi = new javax.swing.JRadioButton();
jLabel8 = new javax.swing.JLabel();
blncmb = new javax.swing.JComboBox<>();
jLabel11 = new javax.swing.JLabel();
jLabel12 = new javax.swing.JLabel();
txfhargatiket = new javax.swing.JTextField();
tglcmb = new javax.swing.JComboBox<>();
tahuncmb = new javax.swing.JComboBox<>();
jPanel2 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
txfnama = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txftotal = new javax.swing.JTextField();
txfjmltiket = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
btnreset = new javax.swing.JButton();
btncetak = new javax.swing.JButton();
btnkeluar = new javax.swing.JButton();
jLabel7 = new javax.swing.JLabel();
jLabel15 = new javax.swing.JLabel();
jTextField2.setText("jTextField2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(255, 204, 204));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
});
jLabel1.setFont(new java.awt.Font("Pristina", 1, 25)); // NOI18N
jLabel1.setText("Pesan Tiket Online LRT Antar Kota");
pnlprint.setBackground(new java.awt.Color(153, 153, 255));
jLabel2.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel2.setText("Pilih Destinasi Tujuan");
Listtujuancmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
Listtujuancmb.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "----- Pilih Tujuan -----", "Tangerang - Bekasi", "Tangerang - Bogor", "Tangerang - Depok", "Tangerang - Jakarta Barat", "Tangerang - Jakarta Pusat", "Tangerang - Jakarta Selatan", "Tangerang - Jakarta Timur", "Tangerang - Jakarta Utara" }));
Listtujuancmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ListtujuancmbActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel3.setText("Jenis Kereta");
btngjnskereta.add(RBeksekutif);
RBeksekutif.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
RBeksekutif.setText("Eksekutif");
RBeksekutif.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RBeksekutifActionPerformed(evt);
}
});
btngjnskereta.add(RBekonomi);
RBekonomi.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
RBekonomi.setText("Ekonomi");
RBekonomi.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
RBekonomiActionPerformed(evt);
}
});
jLabel8.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel8.setText("Pilih Tanggal Keberangkatan");
blncmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
blncmb.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Bulan", "Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember" }));
blncmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
blncmbActionPerformed(evt);
}
});
jLabel11.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel11.setText("Harga/tiket");
jLabel12.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel12.setText("Rp.");
txfhargatiket.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tglcmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tahuncmb.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
tahuncmb.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tahuncmbActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlprintLayout = new javax.swing.GroupLayout(pnlprint);
pnlprint.setLayout(pnlprintLayout);
pnlprintLayout.setHorizontalGroup(
pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlprintLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlprintLayout.createSequentialGroup()
.addComponent(tglcmb, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(blncmb, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tahuncmb, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlprintLayout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel12)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txfhargatiket))
.addGroup(pnlprintLayout.createSequentialGroup()
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addGroup(pnlprintLayout.createSequentialGroup()
.addComponent(RBekonomi)
.addGap(28, 28, 28)
.addComponent(RBeksekutif))
.addComponent(jLabel8)
.addComponent(jLabel3))
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(Listtujuancmb, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
pnlprintLayout.setVerticalGroup(
pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlprintLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Listtujuancmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(RBekonomi)
.addComponent(RBeksekutif))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel12)
.addComponent(txfhargatiket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(11, 11, 11)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlprintLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(blncmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tglcmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(tahuncmb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(218, 218, 218))
);
jPanel2.setBackground(new java.awt.Color(255, 255, 102));
jLabel4.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel4.setText("Nama Lengkap");
txfnama.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel5.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel5.setText("Jumlah Tiket");
jLabel6.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel6.setText("Total");
txftotal.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txfjmltiket.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
txfjmltiket.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txfjmltiketActionPerformed(evt);
}
});
txfjmltiket.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
txfjmltiketKeyReleased(evt);
}
});
jLabel10.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel10.setText("Tiket");
btnreset.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btnreset.setText("Cancel");
btnreset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnresetActionPerformed(evt);
}
});
btncetak.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btncetak.setText("Pesan");
btncetak.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btncetakActionPerformed(evt);
}
});
btnkeluar.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
btnkeluar.setText("Keluar");
btnkeluar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnkeluarActionPerformed(evt);
}
});
jLabel7.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jLabel7.setText("Rp.");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)
.addComponent(jLabel6)
.addComponent(jLabel5))
.addGap(10, 10, 10)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txfnama)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(txfjmltiket, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel10)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txftotal, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btnreset, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnkeluar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(6, 6, 6))))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(btncetak, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txfnama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5)
.addComponent(txfjmltiket, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel10))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel6)
.addComponent(txftotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btncetak)
.addComponent(btnreset)
.addComponent(btnkeluar))
.addContainerGap(45, Short.MAX_VALUE))
);
jLabel15.setFont(new java.awt.Font("Pristina", 1, 20)); // NOI18N
jLabel15.setText("Via Kota Tangerang");
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()
.addGap(0, 35, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlprint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(34, 34, 34))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel15)
.addGap(127, 127, 127))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel15)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlprint, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(29, 29, 29))
);
pack();
}// </editor-fold>
private void RBekonomiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Menampilkan harga tiket setelah pilih jenis kereta ekonomi
if(RBekonomi.isSelected()){
txfhargatiket.setText(String.valueOf(ekonomi));
RBeksekutif.setSelected(false);
}
}
private void RBeksekutifActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Menampilkan harga tiket setelah pilih jenis kereta eksekutif
if(RBeksekutif.isSelected()){
txfhargatiket.setText(String.valueOf(eksekutif));
RBekonomi.setSelected(false);
}
}
private void ListtujuancmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//kondisi untuk menetukan harga sesuai pilihan
if(Listtujuancmb.getSelectedItem().equals("----- Pilih Tujuan -----")){
btngjnskereta.clearSelection();
txfhargatiket.setText("");
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Bekasi")){
ekonomi=43000;
eksekutif=53000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Bogor")){
ekonomi=50000;
eksekutif=60000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Depok")){
ekonomi=40000;
eksekutif=55000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Barat")){
ekonomi=15000;
eksekutif=25000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Pusat")){
ekonomi=25000;
eksekutif=40000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Selatan")){
ekonomi=20000;
eksekutif=35000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Timur")){
ekonomi=30000;
eksekutif=45000;
}
else if(Listtujuancmb.getSelectedItem().equals("Tangerang - Jakarta Utara")){
ekonomi=20000;
eksekutif=35000;
}
}
private void formWindowActivated(java.awt.event.WindowEvent evt) {
// TODO add your handling code here:
int i;
for(i=1;i<=31;i++){
tglcmb.addItem(""+i);
}
int k;
for(k=2019;k<=2100;k++)
{
tahuncmb.addItem(""+k);
}
}
private void blncmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void tahuncmbActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void btnkeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
//Untuk membuat tombol keluar berfungsi
this.dispose();
}
private void btncetakActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Fungsi Code ini untuk mengaktifkan fungsi tombol pesan
JOptionPane.showMessageDialog(this, "Terima Kasih. Permintaan anda sedang diproses"
+ "\n Silahkan menunggu email atau pesan kode"
+ "\n pembayaran dari kami.");
}
private void btnresetActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Untuk pengeksekusian atau membuat tombol reset/cancel berfungsi
Listtujuancmb.setSelectedItem("----- Pilih Tujuan -----");
RBekonomi.isSelected();
RBeksekutif.isSelected();
txfhargatiket.setText("");
tglcmb.setSelectedItem("1");
blncmb.setSelectedItem("Bulan");
tahuncmb.setSelectedItem("2019");
txfnama.setText("");
txfjmltiket.setText("");
txftotal.setText("");
}
private void txfjmltiketKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
// Ini adalah pendeklarasian rumus dari pembelian tiket
int a, b, c;
a=Integer.valueOf(txfjmltiket.getText());
b=Integer.valueOf(txfhargatiket.getText());
c=a*b;
txftotal.setText(""+c);
}
private void txfjmltiketActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Saat kita menginput jumlah tiket, maka secara otomatis kita akan mengetahui harga tiket dan total harga tiket
jumlah=Integer.parseInt(txfjmltiket.getText());
harga=Integer.parseInt(txfhargatiket.getText());
total=jumlah*harga;
txftotal.setText(String.valueOf(total));
}
/**
* @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(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TiketKereta.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TiketKereta.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 TiketKereta().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JComboBox<String> Listtujuancmb;
private javax.swing.JRadioButton RBekonomi;
private javax.swing.JRadioButton RBeksekutif;
private javax.swing.JComboBox<String> blncmb;
private javax.swing.JButton btncetak;
private javax.swing.ButtonGroup btngjnskereta;
private javax.swing.ButtonGroup btngkeluar;
private javax.swing.JButton btnkeluar;
private javax.swing.JButton btnreset;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel15;
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.JPanel jPanel2;
private javax.swing.JTextField jTextField2;
private javax.swing.JPanel pnlprint;
private javax.swing.JComboBox<String> tahuncmb;
private javax.swing.JComboBox<String> tglcmb;
private javax.swing.JTextField txfhargatiket;
private javax.swing.JTextField txfjmltiket;
private javax.swing.JTextField txfnama;
private javax.swing.JTextField txftotal;
// End of variables declaration
}
Terima kasih sudah berkunjung ke blog saya, semoga saya buat artikel lagi bulan depan. :)
Komentar
Posting Komentar