Cara Membuat Aplikasi Tiket Kereta - GUI NeatBeans
Assalamualaikum
Wr. Wb.
Nama : Arsy Eric Erian
NIM : 193140914111072
Kelas : SI-B
Fakultas : Pendidikan Vokasi
Untuk
Tugas Kali ini yang ingin saya bahas adalah bagaimana membuat Form Aplikasi
Penjualan Tiket Kereta Api menggunakan Bahasa Pemograman Java NetBeans
Ubahlah properties nama dari setiap component atau atribut sebagai berikut:
Object
|
Variable Name
|
Text
|
jLabel1
|
jLabel1
|
Penjualan
Tiket Kereta Api Blitar
|
jLabel2
|
jLabel2
|
Jurusan
|
jLabel3
|
jLabel3
|
Jenis
|
jLabel4
|
jLabel4
|
Harga
|
jLabel5
|
jLabel5
|
Nomor Kursi
|
jLabel6
|
jLabel6
|
Nama
Penumpang
|
jLabel7
|
jLabel7
|
Jumlah Beli
|
jLabel8
|
jLabel8
|
Total Bayar
|
jLabel9
|
jLabel9
|
Uang Bayar
|
JLabel10
|
JLabel10
|
Uang Kembali
|
jTextField1
|
txt_harga
|
“Kosongkan”
|
jTextField2
|
txt_nomor
|
“Kosongkan”
|
jTextField3
|
txt_nama
|
“Kosongkan”
|
jTextField4
|
txt_jumlah
|
“Kosongkan”
|
jTextField5
|
txt_total
|
“Kosongkan”
|
jTextField6
|
txt_bayar
|
“Kosongkan”
|
jTextField7
|
txt_pembayaran
|
“Kosongkan”
|
jRadioButton1
|
rb_express
|
Gajayana Luxury
|
jRadioButton2
|
rb_eksekutif
|
Malabar (Eksekutif)
|
jRadioButton3
|
rb_bisnis
|
Malabar (Bisnis)
|
jRadioButton4
|
rb_ekonomi
|
Malioboro
|
jButton1
|
btn_input
|
Input Lagi
|
jButton2
|
btn_cetak
|
Cetak
|
jButton3
|
btn_keluar
|
Keluar
|
jComboBox1
|
jurusan
|
Pilih, Surabaya, Yogyakarta, Bandung, Jakarta
|
txt_area
|
txt_area
|
“Kosongkan”
|
Berikut
ini adalah listing Kodenya: Saya jabarkan satu persatu.
Sebelum memulai pengkodeannya kita
harus mengimprort dahulu seperti dibawah ini
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableModel;
Buat variable terlebih dahulu untuk
proses perhitungan yang akan dilakukan. taruh pada public class JFrameKRL
extends javax.swing.JFrame, seperti yang dibawah ini;
int max=0;int express, bisnis, eksekutif, ekonomi, harga, beli, total, bayar, kembali;
public Perulangantiketkeretaapi() {
initComponents();
}
private void rb_ekonomiActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb_ekonomi.isSelected()){
txt_harga.setText(String.valueOf(ekonomi));
}
}
private void rb_eksekutifActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Menampilkan harga setelah memilih jenis kelas
if(rb_eksekutif.isSelected()){
txt_harga.setText(String.valueOf(eksekutif));
}
}
private void jurusanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Membuat kondisi untuk menentukan harga sesuai jurusan
if(jurusan.getSelectedItem().equals("Pilih Jurusan")){
buttonGroup1.clearSelection();
txt_harga.setText("");
}
else if(jurusan.getSelectedItem().equals("Malang")){
express=1100000;
eksekutif=345000;
bisnis=205000;
ekonomi=140000;
}
else if(jurusan.getSelectedItem().equals("Yogyakarta")){
express=1500000;
eksekutif=420000;
bisnis=250000;
ekonomi=165000;
}
else if(jurusan.getSelectedItem().equals("Bandung")){
express=2200000;
eksekutif=820000;
bisnis=490000;
ekonomi=325000;
}
else if(jurusan.getSelectedItem().equals("Jakarta")){
express=2500000;
eksekutif=900000;
bisnis=630000;
ekonomi=452000;
}
}
private void txt_jumlahActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
// Menginput jumlah tiket dan mengetahui total pembayaran
beli=Integer.parseInt(txt_jumlah.getText());
harga=Integer.parseInt(txt_harga.getText());
total=bayar*harga;
txt_total.setText(String.valueOf(total));
}
private void txt_bayarActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here:
// Menginput jumlah tiket dan mengetahui total pembayaran
bayar=Integer.parseInt(txt_bayar.getText());
kembali=Integer.parseInt(txt_total.getText());
total=bayar-kembali;
txt_kembalian.setText(String.valueOf(total));
}
private void txt_jumlahKeyReleased(java.awt.event.KeyEvent evt) { // TODO add your handling code here:
int a, b, c;
a=Integer.valueOf(txt_harga.getText());
b=Integer.valueOf(txt_jumlah.getText());
c=a*b;
txt_total.setText(""+c);
}
private void txt_bayarKeyReleased(java.awt.event.KeyEvent evt) { // TODO add your handling code here:
int a, b, c;
a=Integer.valueOf(txt_bayar.getText());
b=Integer.valueOf(txt_total.getText());
c=a-b;
txt_kembalian.setText(""+c);
}
private void btn_inputActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
buttonGroup1.clearSelection();
txt_harga.setText("");
txt_nomor.setText("");
txt_nama.setText("");
txt_total.setText("");
txt_jumlah.setText("");
txt_bayar.setText("");
txt_kembalian.setText("");
jurusan.setSelectedItem("Pilih Jurusan");
}
private void btn_keluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int answer= JOptionPane.showConfirmDialog(null,"Anda Yakin Keluar","Keluar", JOptionPane.OK_OPTION);
if(answer==JOptionPane.OK_OPTION){
dispose();
}
}
private void btn_cetakActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
btn_cetak.setText((String)jurusan.getSelectedItem());
txt_area.setText(
"Nomor Kursi :"+txt_nomor.getText()+"\n"+
"Nama Penumpang :"+txt_nama.getText()+"\n"+
"Jumlah Beli :"+txt_jumlah.getText()+"\n"+
"Total Bayar :"+txt_total.getText()+"\n"+
"Uang Bayar :"+txt_bayar.getText()+"\n"+
"Uang Kembali :"+txt_kembalian.getText()+"\n");
}
private void rb_expressActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:*
if(rb_express.isSelected()){
txt_harga.setText(String.valueOf(express));
}
}
private void rb_bisnisActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(rb_bisnis.isSelected()){
txt_harga.setText(String.valueOf(bisnis));
}
}
Selanjutnya public static void main(String args[]) {
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(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.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() {
JOptionPane.showMessageDialog(null, "Selamat Datang Di Stasiun Blitar");
new Perulangantiketkeretaapi().setVisible(true);
}
});
}
/* 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(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Perulangantiketkeretaapi.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() {
JOptionPane.showMessageDialog(null, "Selamat Datang Di Stasiun Blitar");
new Perulangantiketkeretaapi().setVisible(true);
}
});
}
Berikut
ini adalah hasil proram setelah dijalankan
Awalnya
akan muncul JOptionPane seperti dibawh
ini;
Wassalamualaikum Wr. Wb.
Tidak ada komentar:
Posting Komentar