Anda di halaman 1dari 18

TUGAS AKHIR

BAHASA PEMOGRAMAN II
APLIKASI RENTAL MOBIL MENGGUNAKAN NETBEAN

Dosen : Rahmaddeni, M.Kom

Disusun Oleh:

Gilang Citra Lenardo (16081038)

PROGRAM STUDI TEKNIK INFORMATIKA


SEKOLAH TINGGI MANAJEMEN INFORMATIKA DAN
KOMPUTER
HANGTUAH PEKANBARU
2018
Membuat Aplikasi Rental Mobil Menggunakan NetBeans

Langkah 1

1. Buatlah sebuah project baru

2. Buka source package, lalu klik kanan  New  JFrame Form

3. Beri nama form Login, form ini akan digunakan sebagai login ke aplikasi

2
4. Desain form seperti gambar berikut

jLabel4

jLabel1

jLabel2
username
jLabel3
Password

jButton1

5. Klik 2x pada jButton1, lalu ketikkan script berikut

6. Kembali ke form, kemudian klik kanan pada text field “password” pilih event 
key  key  keyPressed

3
7. Ketik script berikut

8. Kemudian klik 2x pada jButton4, lalu ketik script berikut

9. Berikut script lengkapnya :

package aplikasirentalmobil;

import java.awt.event.KeyEvent;

import javax.swing.JOptionPane;

public class Login extends javax.swing.JFrame {

private Aplikasi a;

public Login() {

initComponents();

a=new Aplikasi();

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

username = new javax.swing.JTextField();

password = new javax.swing.JPasswordField();

4
jButton1 = new javax.swing.JButton();

jLabel4 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setUndecorated(true);

setResizable(false);

jLabel1.setFont(new java.awt.Font("Century Gothic", 1, 24)); // NOI18N

jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

jLabel1.setText("MEMBER LOGIN");

jLabel2.setText("Username");

jLabel3.setText("Password");

password.addKeyListener(new java.awt.event.KeyAdapter() {

public void keyPressed(java.awt.event.KeyEvent evt) {

passwordKeyPressed(evt);

});

jButton1.setText("Login");

jButton1.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

jButton1ActionPerformed(evt);

});

jLabel4.setFont(new java.awt.Font("Century Gothic", 1, 14)); // NOI18N

jLabel4.setText("x");

jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) {

jLabel4MouseClicked(evt);

});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

5
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(password)

.addComponent(username)

.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,


Short.MAX_VALUE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel2)

.addComponent(jLabel3))

.addGap(0, 0, Short.MAX_VALUE))

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addGap(0, 0, Short.MAX_VALUE)

.addComponent(jLabel4)))

.addContainerGap())

.addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 247,


Short.MAX_VALUE)

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel4)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addComponent(jLabel1)

.addGap(18, 18, 18)

.addComponent(jLabel2)

.addGap(2, 2, 2)

.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

6
.addComponent(jLabel3)

.addGap(1, 1, 1)

.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)

.addComponent(jButton1)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

pack();

setLocationRelativeTo(null);

}// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

if (username.getText().equals("admin") && password.getText().equals("admin")){

a.setVisible(true);

this.dispose();

else{

JOptionPane.showMessageDialog(this, "Username & Password Salah ");

username.setText("");

password.setText("");

private void passwordKeyPressed(java.awt.event.KeyEvent evt) {

if(evt.getKeyCode()==KeyEvent.VK_ENTER)

if (username.getText().equals("admin") && password.getText().equals("admin")){

a.setVisible(true);

this.dispose();

else{

JOptionPane.showMessageDialog(this, "Username & Password Salah ");

7
username.setText("");

password.setText("");

private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {

{System.exit(0);}

/**

* @param args the command line arguments

*/

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Login().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton jButton1;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JPasswordField password;

private javax.swing.JTextField username;

// End of variables declaration

8
10. Buat form baru, beri nama Aplikasi

11. Buat desain form seperti berikut:

jLabel15

jTextField1

jTextField2

jComboBox1

jComboBox3
jComboBox2

jTextField4
jTextField3

jTextField7
jTextField6

jTextField8
jButton2

jTextField9
jButton1

jButton3
12. Masukan script berikut untuk memanggil form cetak

9
13. Kembali ke form, lalu klik kanan pada bagian form yang kosong. Pilih event 
window  window Activated, kemudian ketik script berikut

Script diatas untuk menampilkan tanggal secara otomatis pada saat aplikasi
dibuka.

14. Klik kanan pada jComboBox1, pilih Event  Action  actionPerformed. Ketik
script dibawah untuk menampilkan merek mobil dan harga sewa sesuai plat
nomor yg dipilih.

10
15. Klik kanan pada jComboBox2, pilih Event  Action  actionPerformed. Ketik
script dibawah untuk pilihan menggunakan jasa supir atau tidak.

16. Klik kanan pada jTextField8, pilih Event  Key  KeyPressed, kemudian ketik
script dibawah untuk menghitung uang kembalian. Uang kembali akan dihitung
otomatis setelah tekan enter pada keyboard

17. Klik kanan pada jButton2, pilih Event  Action  actionPerformed, ketik script
dibawah untuk menghitung total bayar.

11
18. Klik kanan pada jButton1, pilih Event  Action  actionPerformed, ketik script
dibawah untuk menampilkan input baru dengan mengosongka semua field.

19. Klik kanan pada jLabel15, pilih Event  Mouse mouseClicked, ketik script
dibawah untuk menutup form.

20. Klik kanan pada jComboBox3, pilih Event  Mouse mouseClicked, ketik script
dibawah untuk menampilkan lama hari sewa.

21. Berikut script lengkap pada form aplikasi

package aplikasirentalmobil;

import java.awt.event.KeyEvent;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
public class Aplikasi extends javax.swing.JFrame {
private Cetak c;
public Aplikasi() {

12
initComponents();
c=new Cetak();
}

private void formWindowActivated(java.awt.event.WindowEvent evt) {


SimpleDateFormat sdf=new SimpleDateFormat("dd MMM YYYY");
Calendar cal=Calendar.getInstance();
jTextField2.setText(sdf.format(cal.getTime()));
jTextField10.setVisible(false);
jTextField11.setVisible(false);
jTextField4.setText("0");
jTextField6.setText("0");
}

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {


DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
DecimalFormatSymbols formatRp = new DecimalFormatSymbols();
formatRp.setCurrencySymbol("Rp. ");
formatRp.setMonetaryDecimalSeparator(',');
formatRp.setGroupingSeparator('.');
kursIndonesia.setDecimalFormatSymbols(formatRp);
if
(jComboBox1.getSelectedItem().equals("BM.111.A"))
{
jTextField3.setText("Xenia");
jTextField4.setText(kursIndonesia.format(300000));
jTextField11.setText("300000");
}
else
if
((jComboBox1.getSelectedItem().equals("BM.222.B")))
{
jTextField3.setText("Avanza");
jTextField4.setText(kursIndonesia.format(350000));
jTextField11.setText("350000");
}
else
if
((jComboBox1.getSelectedItem().equals("BM.333.C")))
{
jTextField3.setText("Ertiga");
jTextField4.setText(kursIndonesia.format(250000));
jTextField11.setText("250000");
}
else
if
((jComboBox1.getSelectedItem().equals("BM.444.D")))
{
jTextField3.setText("Innova");
jTextField4.setText(kursIndonesia.format(400000));
jTextField11.setText("400000");
}
}

private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {


if
(jComboBox2.getSelectedItem().equals("Jasa Supir"))
{
jTextField6.setText("100000");
}
else
if
(jComboBox2.getSelectedItem().equals("Non Supir"))
{
jTextField6.setText("0");
}

13
}

private void jTextField8KeyPressed(java.awt.event.KeyEvent evt) {


if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
DecimalFormatSymbols formatRp = new DecimalFormatSymbols();
formatRp.setCurrencySymbol("Rp. ");
formatRp.setMonetaryDecimalSeparator(',');
formatRp.setGroupingSeparator('.');
kursIndonesia.setDecimalFormatSymbols(formatRp);
int bayar=Integer.parseInt(jTextField10.getText());
int uangbayar=Integer.parseInt(jTextField8.getText());
int uangkembali=(uangbayar-bayar);
jTextField9.setText(kursIndonesia.format(uangkembali));
}
}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {


DecimalFormat kursIndonesia = (DecimalFormat) DecimalFormat.getCurrencyInstance();
DecimalFormatSymbols formatRp = new DecimalFormatSymbols();
formatRp.setCurrencySymbol("Rp. ");
formatRp.setMonetaryDecimalSeparator(',');
formatRp.setGroupingSeparator('.');
kursIndonesia.setDecimalFormatSymbols(formatRp);

String lamasewa=String.valueOf(jComboBox3.getSelectedItem());
int lama=Integer.parseInt(lamasewa);
int hargasewa=Integer.parseInt(jTextField11.getText());
int biayasupir=Integer.parseInt(jTextField6.getText());
int bayar=(lama*hargasewa+biayasupir);
jTextField7.setText(kursIndonesia.format(bayar));
jTextField10.setText(Integer.toString(bayar));
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {


jTextField1.setText("");
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Calendar cal=Calendar.getInstance();
jTextField2.setText(sdf.format(cal.getTime()));
jTextField3.setText("");
jTextField4.setText("");
jTextField6.setText("");
jTextField7.setText("");
jTextField8.setText("");
jTextField9.setText("");
}

private void jLabel15MouseClicked(java.awt.event.MouseEvent evt) {


int result=JOptionPane.showConfirmDialog(rootPane,"Apakah Anda yakin ingin keluar?");
if (result==JOptionPane.YES_OPTION)
{System.exit(0);}
}

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {


String lamasewa=String.valueOf(jComboBox3.getSelectedItem());
c.ta(jTextField1.getText(),jTextField2.getText(), (String)
jComboBox1.getSelectedItem(),jTextField3.getText(),jTextField4.getText(), lamasewa, (String)
jComboBox2.getSelectedItem(),jTextField6.getText(),jTextField7.getText());
c.setVisible(true);
this.dispose();
}

private void jComboBox3MouseClicked(java.awt.event.MouseEvent evt) {


int n=1;
do {

14
jComboBox3.addItem(n);
n++;
}while (n <=30);
}

22. Buat lagi sebuah form baru dan beri nama Cetak

23. Desain form seperti berikut:

ta

B2

24. Ketik script berikut untuk kembali ke form aplikasi

15
25. Ketik script berikut untuk menampilkan data pada text area (ta)

26. Klik kanan pada b2, pilih Event  Action  actionPerformed, ketik script berikut
untuk kembali ke form aplikasi ketika tombol “OK” di klik.

27. Berikut script lengkap pada form Cetak

package aplikasirentalmobil;

public class Cetak extends javax.swing.JFrame {

private Aplikasi b;

public Cetak() {
initComponents();
}

public void ta(String notrans, String tgl, String nopol, String kendaraan, String harga, String lamasewa, String supir,String
biayasupir,String total){
ta.setText("Struk Pembayaran Rental Mobil"+"\n======================="+"\nNo. Transaksi : "+notrans+"\nTanggal :
"+tgl+"\n\nNo. Polisi : "+nopol+"\nJenis Kendaraan : "+kendaraan+"\n\nHarga Sewa : "+harga+"\nLama Sewa :
"+lamasewa+"\n\nSupir : "+supir+"\nBiaya Supir : "+biayasupir+"\n\n========================"+"\nTotal : "+total);
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();


ta = new javax.swing.JTextArea();
b2 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setUndecorated(true);

ta.setColumns(20);
ta.setRows(5);
jScrollPane1.setViewportView(ta);

b2.setText("OK");
b2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b2ActionPerformed(evt);
}
});

16
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 319,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(139, 139, 139)
.addComponent(b2, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
.addGap(130, 130, 130)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(b2)
.addGap(6, 6, 6))
);

pack();
setLocationRelativeTo(null);
}// </editor-fold>

private void b2ActionPerformed(java.awt.event.ActionEvent evt) {


b=new Aplikasi();
b.setVisible(true);
this.dispose();
}

28. Jalankan aplikasi dengan tekan f6 pada keyboard atau klik tombol run pada
menu bar seperti gambar dibawah:

29. Login dengan username “admin” dan password “admin” lalu enter atau klik
tombol login

17
30. Setelah berhasil login, pilih No. Polisi, Lama Sewa dan Pilihan Supir. Kemudian
klik Hitung. Setelah terhitung, kemudian klik Cetak

31. Berikut hasilnya

32. Selesai

18