Selasa, 13 Juni 2017

Laporan Praktikum Pemograman Web 1 Modul 9 (PHP CRUD)

LAPORAN PRAKTIKUM
Pemograman WEB 1
Modul 9
“PHP CRUD”

Nama         : Radea Nurlaila
NIM           : 2015091083
Prodi          : SI 2015 C

LABORATORIUM KOMPUTER
FAKULTAS ILMU KOMPUTER
UNIVERSITAS KUNINGAN
2017
Jl. Cut NyakDien, No.36A CijohoKuninganTelp/Faks : 0232-974824

 

 

1. PRAKTIKUM

Membuat script php dan MySQL untuk menampilkan tabel mahasiswa ke dalam web

1.Buat database dengan nama db_fkom, kemudian buat tabel mahasiswa seperti berikut





2. Setelah tabel dibuat, lalu buat script koneksi.php untuk mengkoneksikan web dengan database

<?php
$db_host = "localhost";
$db_user = "root";
$db_pass = "";

$koneksi = mysql_connect("$db_host", "$db_user", "$db_pass");
$sambung = mysql_select_db("db_fkom",$koneksi);


3. Setelah itu, buat script index.php

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%">
<td colspan="3">
<h2 align="center"> Welcome!</h2>
</td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>

 


4. Setelah file index dibuat, buat file data_mhs.php yang akan digunakan untuk menampilkan data dari tabel mahasiswa

 <title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form id="form1" name="form1" method="post" action="">
<table width="50%" border="2" align="center" valign="top">
<tr>
<td width="20%" align="center"><b> NIM </b></td>
<td width="60%" align="center"><b> Nama </b></td>
<td width="20%" align="center"><b> Jenis Kelamin </b></td>
<td> Aksi</td>
</tr>
<?php
include "koneksi.php";
$query="select * from mahasiswa";
$result=mysql_query($query);
while ($data=mysql_fetch_array($result)) {
?>
<tr>
<td align="center"><a href="edit_mhs.php?nim=<?php echo $data['nim'];?>"><?php echo $data['nim']; ?></a></td>
<td align="center"><?php echo $data['nama']; ?></td>
<td align="center"><?php echo $data['jk']; ?></td>
<td align="center"><a href="delete_mhs.php?nim=<?php echo $data['nim'];?>" onclick="return confirm('Apakah Anda Yakin akan menghapus data ini?')" title="delete">Delete</a></td>
</tr>
<?php
}
?>



<center><a href="input_mhs.php"> Tambah Data </a></center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>


5. Lalu buat file input_mhs.php untuk menampilkan form yang akan digunakan untuk meng-inputkan data ke dalam tabel mahasiswa

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form name="input" method="post" action="input_mhs.php">
<table border="0" align="center">
<tr>
<td> NIM</td>
<td><input type="text" name="nim" size="20" maxlength="15"></td>
</tr>
<tr>
<td> Nama</td>
<td><input type="text" name="nama" size="40" maxlength="30"></td>
</tr>
<tr>
<td> Jenis Kelamin</td>
<td><input type="radio" name="jk" value="L" id="jk1">L
<input type="radio" name="jk" value="P" id="jk2">P</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="simpan" value="Simpan"></td>
</tr>
<?php
extract($_POST);
if(isset($simpan)) {
include "koneksi.php";
$input="insert into mahasiswa values('$nim','$nama','$jk')";
$save=mysql_query($input);
if($save) {
?>
<script lang="javascript">
 alert("Data Berhasil dimasukan");
 document.location="data_mhs.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal dimasukan");
 document.location="input_mhs.php";
 </script>
<?php
}
}
?>



<center> Form Input Data Mahasiswa </center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>
 

 6. Lalu buat file edit_mhs.php untuk mengedit data yang ada dalam tabel mahasiswa

<?php
include "koneksi.php";
$query="select * from mahasiswa where nim='$_GET[nim]'";
$result=mysql_query($query);
while ($data=mysql_fetch_array($result)) {
$n=$data['nim'];
$nm=$data['nama'];
$j=$data['jk'];
}
?>

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form name="edit" method="post" action="edit_mhs.php">
<table border="0" align="center">
<tr>
<td> NIM</td>
<td> : <input type="text" name="nim" size="20" maxlenght="15" value="<?php echo $n; ?>" readonly></td>
</tr>
<tr>
<td> Nama</td>
<td> : <input type="text" name="nama" size="40" maxlenght="30" value="<?php echo $nm; ?>"></td>
</tr>
<tr>
<td> Jenis Kelamin</td>
<?php
if($j=="L") {
?>
<td> : <input type="radio" name="jk" value="L" id="jk1" checked>L
<input type="radio" name="jk" value="P" id="jk2">P</td>
<?php
} else {
?>
<td> : <input type="radio" name="jk" value="L" id="jk1">L
<input type="radio" name="jk" value="P" id="jk2" checked>P</td>
<?php
}
?></tr>
<tr>
<td colspan="2"><input type="submit" name="edit" value="Edit"></tr>
<?php
extract($_POST);
if(isset($edit)) {
$input="update mahasiswa set nama='$nama', jk='$jk' where nim='$nim'";
$save=mysql_query($input);
if($save) {
?>
<script lang="javascript">
 alert("Data Berhasil Diupdate");
 document.location="data_mhs.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal Diupdate");
 document.location="edit_mhs.php";
 </script>
<?php
}
}
?>



<center> Form Edit Data Mahasiswa </center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>

 


 7. Dan yang terakhir buat file delete_mhs.php untuk menghapus data dalam tabel mahasiswa

<?php
include "koneksi.php";
$query="delete from mahasiswa where nim='$_GET[nim]'";
$delete=mysql_query($query);
if($delete) {
?>
<script lang="javascript">
 alert("Data Berhasil Dihapus");
 document.location="data_mhs.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal Dihapus");
 document.location="data_mhs.php";
 </script>
<?php
}
?>

 


8. Run Program, maka hasilnya adalah






TUGAS

Tambahkan tabel matkul dalam database lalu buat script php dan MySQL untuk menampilkan tabel dan menambah data ke dalam tabel


1. Pertama buat database matkul 




2. Buat file data_mk.php , scriptnya adalah :

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form id="form1" name="form1" method="post" action="">
<table width="50%" border="2" align="center" valign="top">
<tr>
<td width="40%" align="center"><b> Kode Mata Kuliah </b></td>
<td width="40%" align="center"><b> Nama Mata Kuliah </b></td>
<td width="20%" align="center"><b> Semester </b></td>
</tr>
<?php
include "koneksi.php";
$query="select * from matkul";
$result=mysql_query($query);
while ($data=mysql_fetch_array($result)) {
?>
<tr>
<td align="center"><?php echo $data['kd_mk']; ?></td>
<td align="center"><?php echo $data['nama_mk']; ?></td>
<td align="center"><?php echo $data['semester']; ?></td>
</tr>
<?php
}
?>
 
<center><a href="input_mk.php"> Tambah Data </a></center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>

3. Setelah itu buat file input_mk.php untuk menambahkan data ke dalam tabel matkul

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form name="input" method="post" action="input_mk.php">
<table border="0" align="center">
<tr>
<td> Kode Mata Kuliah</td>
<td><input type="text" name="kd_mk" size="40" maxlength="15"></td>
</tr>
<tr>
<td> Nama Mata Kuliah</td>
<td><input type="text" name="nama_mk" size="40" maxlength="30"></td>
</tr>
<tr>
<td> Semester</td>
<td><input type="text" name="semester" size="40" maxlength="30"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="simpan" value="Simpan"></td>
</tr>
<?php
extract($_POST);
if(isset($simpan)) {
include "koneksi.php";
$input="insert into matkul values('$kd_mk','$nama_mk','$semester')";
$save=mysql_query($input);
if($save) {
?>
<script lang="javascript">
 alert("Data Berhasil dimasukan");
 document.location="data_mk.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal dimasukan");
 document.location="input_mk.php";
 </script>
<?php
}
}
?>

<center> Form Input Data Mata Kuliah </center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>


Maka Hasilnya adalah : klik tambah data




 

POST TEST

Tambahkan tabel prodi dalam database lalu buat script php dan MySQL untuk menampilkan tabel ke dalam web dan juga script untuk input, edit dan hapus record


1. Buat tabel prodi dalam database




2. Buat file data_prodi.php

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form id="form1" name="form1" method="post" action="">
<table width="50%" border="2" align="center" valign="top">
<tr>
<td width="30%" align="center"><b> Kode Prodi </b></td>
<td width="40%" align="center"><b> Nama Prodi </b></td>
<td width="17%" align="center"><b> Jenjang </b></td>
<td width="13%" align="center"><b> Aksi </b></td>
</tr>
<?php
include "koneksi.php";
$query="select * from prodi";
$result=mysql_query($query);
while ($data=mysql_fetch_array($result)) {
?>
<tr>
<td align="center"><a href="edit_prodi.php?kd_prodi=<?php echo $data['kd_prodi'];?>"><?php echo $data['kd_prodi']; ?></a></td>
<td align="center"><?php echo $data['nama_prodi']; ?></td>
<td align="center"><?php echo $data['jenjang']; ?></td>
<td align="center"><a href="delete_prodi.php?kd_prodi=<?php echo $data['kd_prodi'];?>" onclick="return confirm('Apakah Anda Yakin akan menghapus data ini?')" title="delete">Delete</a></td>
</tr>
<?php
}
?>

<center><a href="input_prodi.php"> Tambah Data </a></center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>





 3. Lalu buat file input_prodi.php

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form name="input" method="post" action="input_prodi.php">
<table border="0" align="center">
<tr>
<td> Kode Prodi</td>
<td><input type="text" name="kd_prodi" size="40" maxlength="15"></td>
</tr>
<tr>
<td> Nama Prodi</td>
<td><input type="text" name="nama_prodi" size="40" maxlength="30"></td>
</tr>
<tr>
<td> Jenjang</td>
<td><input type="text" name="jenjang" size="40" maxlength="2"></td>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="simpan" value="Simpan"></td>
</tr>
<?php
extract($_POST);
if(isset($simpan)) {
include "koneksi.php";
$input="insert into prodi values('$kd_prodi','$nama_prodi','$jenjang')";
$save=mysql_query($input);
if($save) {
?>
<script lang="javascript">
 alert("Data Berhasil dimasukan");
 document.location="data_prodi.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal dimasukan");
 document.location="input_prodi.php";
 </script>
<?php
}
}
?>

<center> Form Input Data Prodi </center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>


4. buat file edit_prodi.php

<?php
include "koneksi.php";
$query="select * from prodi where kd_prodi='$_GET[kd_prodi]'";
$result=mysql_query($query);
while ($data=mysql_fetch_array($result)) {
$kd=$data['kd_prodi'];
$nmp=$data['nama_prodi'];
$jj=$data['jenjang'];
}
?>

<title> Modul 9 </title>
<table width="70%" height="100%" border="2" align="center">
<tr height="20%" border="0">
<td align="center" width="33%"><a href="data_mhs.php"> Data Mahasiswa </a></td>
<td align="center" width="33%"><a href="data_mk.php"> Data Mata Kuliah </a></td>
<td align="center" width="33%"><a href="data_prodi.php"> Data Prodi </a></td>
</tr>
<tr height="70%" valign="top">
<td colspan="3">
<form name="edit" method="post" action="edit_prodi.php">
<table border="0" align="center">
<tr>
<td> Kode Prodi</td>
<td> : <input type="text" name="kd_prodi" size="20" maxlength="15" value="<?php echo $kd; ?>" readonly></td>
</tr>
<tr>
<td> Nama Prodi</td>
<td> : <input type="text" name="nama_prodi" size="40" maxlength="30" value="<?php echo $nmp; ?>"></td>
</tr>
<tr>
<td> Jenjang</td>
<td> : <input type="text" name="jenjang" size="40" maxlength="30" value="<?php echo $jj; ?>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="edit" value="Edit"></tr>
<?php
extract($_POST);
if(isset($edit)) {
$input="update prodi set nama_prodi='$nama_prodi', jenjang='$jenjang' where kd_prodi='$kd_prodi'";
$save=mysql_query($input);
if($save) {
?>
<script lang="javascript">
 alert("Data Berhasil Diupdate");
 document.location="data_prodi.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal Diupdate");
 document.location="edit_prodi.php";
 </script>
<?php
}
}
?>
 <center> Form Edit Data Prodi </center></table>
</form></td>
</tr>
<tr height="10%">
<td colspan="3">
<center> &copy; Radea Nurlaila </center></td>
</tr>
</table>
 

5. terakhir buat file delete_prodi.php

<?php
include "koneksi.php";
$query="delete from prodi where kd_prodi='$_GET[kd_prodi]'";
$delete=mysql_query($query);
if($delete) {
?>
<script lang="javascript">
 alert("Data Berhasil Dihapus");
 document.location="data_prodi.php";
 </script>
<?php
} else {
?>
<script lang="javascript">
 alert("Data Gagal Dihapus");
 document.location="data_prodi.php";
 </script>
<?php
}

?>








Maka hasilnya adalah :






Laporan Praktikum BP 2 Pertemuan 7 (MVC dalam Desktop)


LAPORAN PRAKTIKUM
Bahasa Pemograman 2
Pertemuan 7
 
MVC dalam desktop
 
 

Nama         : Radea Nurlaila
NIM           : 2015091083
Prodi          : SI 2015 C
 
LABORATORIUM KOMPUTER
FAKULTAS ILMU KOMPUTER
UNIVERSITAS KUNINGAN
2017
                 Jl. Cut NyakDien, No.36A CijohoKuninganTelp/Faks : 0232-974824




1. Buat sebuah database, contohnya adalah database toko_dvd seperti ini 1

2. Buat project baru, contohnya MVC_SIC_2015
3. Setelah itu, add library dengan meng-klik kanan pada Libraries -> Add Library… -> MySQL JDBC Driver

2

4. Lalu buat 6 package baru yaitu tokodvd.koneksi , tokodvd.model, tokodvd.view, tokodvd.controller, tokodvd.DAO, tokodvd.DAOImplement.
Dalam tokodvd.koneksi buat sebuah file Java Class dengan nama Koneksi.
Dalam tokodvd.model buat 2 buah file Java Class bernama supplier dan tableModelSupplier.
Dalam tokodvd.view  buat sebuah file JFrame Form dengan nama FormSupplier.
Dalam tokodvd.controller buat sebuah file Java Class dengan nama controllerSupplier.
Dalam tokodvd.DAO buat sebuah file Java Class dengan nama daoSupplier.
Dalam tokodvd.DAOImplement buat sebuah file Java Implements dengan nama implementsSupplier.
Maka hasilnya akan menjadi seperti ini
3

5. Edit dan Tambahkan scriptnya agar dapat dijalankan. Yang pertama, buka file Koneksi lalu edit agar menjadi seperti ini
4

6. Kemudian buka file supplier dan tambahkan baris ini dibawah nama class
private String idsupplier, nmsupplier, alamat;  
Setelah itu klik kanan pilih Insert Code atau tekan alt+Insert dan akan muncul seperti ini




5

Lalu pilih Getter and Setter. Setelah itu centang semua yang dibutuhkan, dan pilih Generate
6

Maka untuk keseluruhan script untuk supplier yaitu
17

7. Lalu buka file tableModelSupplier dan edit menjadi seperti ini
7

8. Setelah itu buka file FormSupplier dan buat design menjadi seperti ini
8
Untuk text field pada kode ubah menjadi txtidSupplier,
text field pada nama menjadi txtnmSupplier,
text area pada alamat menjadi txtAlamat,
button Insert menjadi buttonInsert,
button Update menjadi buttonUpdate,
button Delete menjadi buttonDelete
button Reset menjadi buttoReset,
button Search menjadi buttonCariNama,
text field dibawah tabel menjadi txtCariNama,
buat tabel menjadi hanya 3 kolom caranya yaitu dengan klik kanan pada tabel lalu pilih Table Contents setelah itu pilih Colums maka kan muncul seperti ini
9
Pilih Table 4 lalu pilih Delete dan klik Close.

9. Setelah itu buka source dan edit scriptnya agar menjadi seperti ini
10_410

10. Lalu kemudian buka file controllerSupplier dan edit menjadi seperti ini
11

11. Setelah itu buka file daoSupplier dan edit menjadi seperti ini
121314

12. Dan yang terakhir buka file implementSupplier dan edit menjadi seperti ini
15

13. Run dan Lihat Hasilnya

Laporan Praktikum BP 2 Pertemuan 6 (Model View Controller)


LAPORAN PRAKTIKUM
Bahasa Pemograman 2
Pertemuan 6
Model View Controller

Nama         : Radea Nurlaila
NIM           : 2015091083
Prodi          : SI 2015 C
LABORATORIUM KOMPUTER
FAKULTAS ILMU KOMPUTER
UNIVERSITAS KUNINGAN
2017
                 Jl. Cut NyakDien, No.36A CijohoKuninganTelp/Faks : 0232-974824

 

 

Menghitung 2 Buah Angka Dengan Menggunakan MVC

1. Buat sebuah project baru. Misalnya  adalah LatMVC



2.Buat 2 buah file Java Class pada package yang tersedia. Caranya yaitu klik kanan pada package lalu pilih New lalu pilih Java Class. Untuk nama filenya, misalnya adalah Controller dan Model




Setelah Java Class dibuat, buat sebuah file JForm dengan nama View

Maka projectnya akan menjadi seperti ini
5

3.. Yang pertama buka file Controller, lalu tambahkan baris dibawah ini, dibawah nama class
private Model mk = new Model();
private View vk;

4. Setelah itu buat method baru, agar lebih mudah caranya yaitu dengan mengklik kanan pada editor lalu pilih Insert Code
28
Setelah itu pilih Constructor
29
Pada Generate Constructor, centang vk : View lalu klik Generate
cats
Maka akan muncul baris ini secara otomatis
30

5. Setelah itu tambahkan baris ini dibawah method sebelumnya
public void Jumlah() {
     mk.Proses(Integer.parseInt(vk.txtBil1.getText()), Integer.parseInt(vk.txtBil2.getText()));
     vk.txtHasil.setText(String.valueOf(mk.Hasil()));
}
6. Maka untuk keseluruhan untuk Controller adalah sebagai berikut

package latmvc;
public class Controller {
    private Model mk = new Model();
    private View vk;

    public Controller(View vk) {
        this.vk = vk;
    }
       public void Jumlah() {
        mk.Proses(Integer.parseInt(vk.txtBil1.getText()), Integer.parseInt(vk.txtBil2.getText()));
        vk.txtHasil.setText(String.valueOf(mk.Hasil()));
    }
}


7. Setelah file Controller selesai dibuat, selanjutnya yaitu membuat pada file Model. Pada file model, edit dan tambahkan baris ini dibawah nama class
public void Proses(int Bil1, int Bil2) {
    this.Bil1=Bil1;
    this.Bil2=Bil2;
}
8. Setelah itu buat method baru. Sintaksnya yaitu
public int Hasil () {
    Hasil = Bil1 + Bil2;
    return Hasil;
}
9. Untuk keseluruhan script Model yaitu

package latmvc;

/**
 *
 * @author Radea
 */
public class Model {
    private int Bil1=0, Bil2=0, Hasil=0;
   
    public void Proses(int Bil1, int Bil2) {
        this.Bil1=Bil1;
        this.Bil2=Bil2;
    }
   
    public int Hasil () {
        Hasil = Bil1 + Bil2;
        return Hasil;
    }
}


10.  Pada View pertama yang perlu dilakukan adalah mendesign tampilannya.
8
Untuk nama variabel yaitu txtBil1 untuk text field Angka 1, txtBil2 untuk text field Angka 2, btnProses untuk button + dan txtHasil untuk text field Hasil
11. Setelah itu, pindah ke source code. Pada source, tambahkan baris ini dibawah nama package
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
12. Lalu tambahkan bari ini dibawah nama class
Controller ck;
13. Tambahkan pula bari ini
public View() {
    initComponents();
    ck=new Controller(this);
}
14. Lalu buat ActionPerformed pada button + dan tambahkan baris ini
ck.Jumlah();
15. Setelah itu buat semua komponen berikut ini yang sebelumnya private menjadi public
11

klik kanan pada komponen yang akan diubah, misalnya adalah button + (btnProses), lalu pilih Properties dan akan muncul jendela Properties seperti ini
31

Lalu pilih Code. Setelah itu pilih Variabel Modifiers, pada Access ubah private mejadi public
27
Lalu klik OK dan Close.

16. klik kanan lalu pilih Run. atau bisa dengan menekan Shift+F6. Maka hasilnya akan menjadi seperti ini







n
21bb




 Kalkulator Dengan Menggunakan MVC

1. buat sebuah project baru dengan nama Calculator.
Lalu buat, package baru dengan nama calculator dan buat sebuah file Java Class dengan nama Main.
Lalu buat package lain dengan nama model dan dalam package model buat sebuah file Java Class dengan nama CalculatorModel.
Setelah itu buat package baru lagi dengan nama view dan dalam package tersebut buat JFrame Form dengan nama CalculatorView.
Maka dalam project ini akan terdapat 3 package dengan masing-masing 1 file di dalam package.

12

2. Setelah itu buka file Main dan tambahkan baris ini dibawah nama package
import view.CalculatorView;
Baris ini digunakan untuk meng-import-kan file CalculatorView yang ada dalam package view
3. Dan tambahkan pula baris ini dibawah method main
new CalculatorView().setVisible(true);
4. Maka untuk keseluruhan sintaks Main adalah


package calculator;

import view.CalculatorView;
/**
 *
 * @author radea
 */
public class Main {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new CalculatorView().setVisible(true);
    }
}


5. Setelah itu buka file CalculatorModel dan tambahkan script ini dibawah nama class
int operator=0;
double operand1;
double operand2;
double result;
6. Tambahkan pula script ini
  public void setOperator(int operator) {
        this.operator = operator;
    }
    public double getResult() {
        return result;
    }
    public void setResult(double hasil) {
        this.result = hasil;
    }
   
    public void process(){
        switch (operator){
            case 1:
                result = operand1 + operand2;
                break;
            case 2:
                result = operand1 – operand2;
                break;
            case 3:
                result = operand1 * operand2;
                break;
            case 4:
                result = operand1 / operand2;
                break;
        }
        operand1=result;
    }
7. Maka keseluruhan script CalculatorModel adalah


package model;

/**
 *
 * @author radea
 */
public class CalculatorModel {
    int operator=0;
    double operand1;
    double operand2;
    double result;

    public void setOperand(String opr) {
        if(!opr.equals("")){
            if(operator==0){
                operand1=Double.valueOf(opr);
            }else{
                operand2=Double.valueOf(opr);
            }
        }
    }

    public void setOperator(int operator) {
        this.operator = operator;
    }

    public double getResult() {
        return result;
    }

    public void setResult(double hasil) {
        this.result = hasil;
    }
  
    public void process(){
        switch (operator){
            case 1:
                result = operand1 + operand2;
                break;
            case 2:
                result = operand1 - operand2;
                break;
            case 3:
                result = operand1 * operand2;
                break;
            case 4:
                result = operand1 / operand2;
                break;
        }
        operand1=result;
    }
}


8. Setelah itu buka CalculatorView dan buat design untuk tampilan seperti ini
16
9. Untuk keseluruhan script CalculatorView adalah
package view;

import java.text.DecimalFormat;
import javax.swing.JOptionPane;
import model.CalculatorModel;

/**
 *
 * @author radea
 */
public class CalculatorView extends javax.swing.JFrame {

    /** Creates new form CalculatorView */
    public CalculatorView() {
        initComponents();
    }

   
    CalculatorModel model = new CalculatorModel();
    String operand="";

    public void getOperand(javax.swing.JButton button){
        operand+=button.getText();
        model.setOperand(operand);
        resultLabel.setText(operand);
    }

    private void getOperator(int opt){
        model.setOperator(opt);
        operand="";
    }
    private void process(){
        DecimalFormat df = new DecimalFormat("#,###.########");
        model.process();
        operand = "";
        resultLabel.setText(df.format(model.getResult())+"");
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        resultLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        button7 = new javax.swing.JButton();
        button4 = new javax.swing.JButton();
        button1 = new javax.swing.JButton();
        buttonKoma = new javax.swing.JButton();
        button11 = new javax.swing.JButton();
        button12 = new javax.swing.JButton();
        button2 = new javax.swing.JButton();
        button3 = new javax.swing.JButton();
        button5 = new javax.swing.JButton();
        button6 = new javax.swing.JButton();
        button8 = new javax.swing.JButton();
        button9 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        buttonBagi = new javax.swing.JButton();
        buttonKali = new javax.swing.JButton();
        buttonKurang = new javax.swing.JButton();
        buttonTambah = new javax.swing.JButton();
        buttonAC = new javax.swing.JButton();
        buttonSamaDengan = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        resultLabel.setBackground(new java.awt.Color(255, 255, 255));
        resultLabel.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 36)); // NOI18N
        resultLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        resultLabel.setText("0");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(resultLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(resultLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        button7.setText("7");
        button7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button7ActionPerformed(evt);
            }
        });

        button4.setText("4");
        button4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button4ActionPerformed(evt);
            }
        });

        button1.setText("1");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });

        buttonKoma.setText(".");
        buttonKoma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonKomaActionPerformed(evt);
            }
        });

        button11.setText("0");
        button11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button11ActionPerformed(evt);
            }
        });

        button12.setText("C");
        button12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button12ActionPerformed(evt);
            }
        });

        button2.setText("2");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });

        button3.setText("3");
        button3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button3ActionPerformed(evt);
            }
        });

        button5.setText("5");
        button5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button5ActionPerformed(evt);
            }
        });

        button6.setText("6");
        button6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button6ActionPerformed(evt);
            }
        });

        button8.setText("8");
        button8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button8ActionPerformed(evt);
            }
        });

        button9.setText("9");
        button9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button9ActionPerformed(evt);
            }
        });

        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()
                        .addComponent(button7, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button8, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button9, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button5, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button6, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(buttonKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button11, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(button12, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(button7, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button8, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button9, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button5, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button6, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonKoma, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button11, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(button12, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        buttonBagi.setText("/");
        buttonBagi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonBagiActionPerformed(evt);
            }
        });

        buttonKali.setText("*");
        buttonKali.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonKaliActionPerformed(evt);
            }
        });

        buttonKurang.setText("-");
        buttonKurang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonKurangActionPerformed(evt);
            }
        });

        buttonTambah.setText("+");
        buttonTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonTambahActionPerformed(evt);
            }
        });

        buttonAC.setText("AC");
        buttonAC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonACActionPerformed(evt);
            }
        });

        buttonSamaDengan.setText("=");
        buttonSamaDengan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSamaDenganActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(buttonBagi, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(buttonAC))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(buttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buttonKurang, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(buttonKali, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(buttonSamaDengan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonBagi, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonAC, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(buttonKali, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonKurang, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonTambah, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(buttonSamaDengan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button1);
    }                                      

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button2);
    }                                      

    private void button3ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button3);
    }                                      

    private void button4ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button4);
    }                                      

    private void button5ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button5);
    }                                      

    private void button6ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button6);
    }                                      

    private void button7ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button7);
    }                                      

    private void button8ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button8);
    }                                      

    private void button9ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        getOperand(button9);
    }                                      

    private void buttonTambahActionPerformed(java.awt.event.ActionEvent evt) {                                            
        getOperator(1);
    }                                           

    private void buttonKurangActionPerformed(java.awt.event.ActionEvent evt) {                                            
       getOperator(2);
    }                                           

    private void buttonKaliActionPerformed(java.awt.event.ActionEvent evt) {                                          
        getOperator(3);
    }                                         

    private void buttonBagiActionPerformed(java.awt.event.ActionEvent evt) {                                          
        getOperator(4);
    }                                         

    private void buttonSamaDenganActionPerformed(java.awt.event.ActionEvent evt) {                                                
        process();
    }                                               

    private void button11ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        getOperand(button11);
    }                                       

    private void buttonKomaActionPerformed(java.awt.event.ActionEvent evt) {                                          
        getOperand(buttonKoma);
    }                                         

    private void button12ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        if(operand.length()>1){
            operand = operand.substring(0, operand.length()-1);
            model.setOperand(operand);
            resultLabel.setText(operand);
        }else{
            operand = "";
            model.setOperand(operand);
            resultLabel.setText("0");
        }      
    }                                       

    private void buttonACActionPerformed(java.awt.event.ActionEvent evt) {                                        
        operand = "";
        model.setOperator(0);
        model.setResult(0);
        resultLabel.setText("0");
    }                                       

    // Variables declaration - do not modify                    
    private javax.swing.JButton button1;
    private javax.swing.JButton button11;
    private javax.swing.JButton button12;
    private javax.swing.JButton button2;
    private javax.swing.JButton button3;
    private javax.swing.JButton button4;
    private javax.swing.JButton button5;
    private javax.swing.JButton button6;
    private javax.swing.JButton button7;
    private javax.swing.JButton button8;
    private javax.swing.JButton button9;
    private javax.swing.JButton buttonAC;
    private javax.swing.JButton buttonBagi;
    private javax.swing.JButton buttonKali;
    private javax.swing.JButton buttonKoma;
    private javax.swing.JButton buttonKurang;
    private javax.swing.JButton buttonSamaDengan;
    private javax.swing.JButton buttonTambah;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel resultLabel;
    // End of variables declaration                  

}
 



10. Lalu klik kanan dan pilih Run atau tekan Shift+F6 untuk menjalankan program. Dan hasilnya akan menjadi seperti ini

23