1.
10. Kharisma 2. 5 3. 9 4.
1+2+3+4+5=15
20. Kharisma 4 6
30. Kharisma 3 3
40. Kharisma 2 0
50. Kharisma 1
Langkah pertama, buat Form seperti pada gambar Berikut :
![]() |
| Gambar 8,7,8.1 Form yang harus dibuat |
Adapun source code menggunakan perintah perulangan "For" sebagai Berikut :
Source code untuk button "Proses Perulangan 1", sebagai berikut :
private void bProses1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=1;b<=a;b++){
areahasil1.append(b+"0.Kharisma\n");
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=1;b<=a;b++){
areahasil1.append(b+"0.Kharisma\n");
}
}
Source code untuk button "Proses Perulangan 2", sebagai berikut:
private void bProses2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=a;b>0;b--){
areahasil2.append(b+"\n");
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=a;b>0;b--){
areahasil2.append(b+"\n");
}
}
Source code untuk button "Proses Perulangan 3", sebagai berikut :
private void bProses3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=a;b>=0;b=b-3){
areahasil3.append(b+"\n");
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
for(b=a;b>=0;b=b-3){
areahasil3.append(b+"\n");
}
}
Source code untuk button "Proses Perulangan 4", sebagai berikut :
private void bProses4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
int jum=0;
a=Integer.parseInt(eBil.getText());
for(b=1;b<=a;b++){
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
}
}
// TODO add your handling code here:
int a,b;
int jum=0;
a=Integer.parseInt(eBil.getText());
for(b=1;b<=a;b++){
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
}
}
Source code untuk button Batal nya yaitu sebagai berikut:
private void bBatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
Dan terakhir source code untuk button Keluar nya yaitu seperti berikut :
private void bKeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
// TODO add your handling code here:
dispose();
}
Adapun source code menggunakan perintah perulangan "While" sebagai Berikut :
Kode program untuk button "Proses Perulangan 1" yaitu sebagai berikut :
private void bProses1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=1;
while(b<=a){
areahasil1.append(b+"0.Kharisma\n");
b++;
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=1;
while(b<=a){
areahasil1.append(b+"0.Kharisma\n");
b++;
}
}
Kode program untuk button "Proses Perulangan 2" yaitu sebagai berikut :
private void bProses2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
while(b>0){
areahasil2.append(b+"\n");
b--;
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
while(b>0){
areahasil2.append(b+"\n");
b--;
}
}
Kode program untuk button "Proses Perulangan 3" yaitu sebagai berikut :
private void bProses3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
while(b>=0){
areahasil3.append(b+"\n");
b=b-3;
}
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
while(b>=0){
areahasil3.append(b+"\n");
b=b-3;
}
}
Kode program untuk button "Proses Perulangan 4" yaitu sebagai berikut :
private void bProses4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
int jum=0;
b=1;
a=Integer.parseInt(eBil.getText());
while(b<=a){
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
b++;
}
}
// TODO add your handling code here:
int a,b;
int jum=0;
b=1;
a=Integer.parseInt(eBil.getText());
while(b<=a){
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
b++;
}
}
Kode program untuk button Batal nya yaitu:
private void bBatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
Kode program untuk button Keluar, seperti berikut :
private void bKeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
// TODO add your handling code here:
dispose();
}
Adapun source code menggunakan perintah perulangan "Do While" sebagai Berikut :
Source code button "Proses Perulangan 1", sebagai berikut :
private void bProses1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=1;
do{
areahasil1.append(b+"0.Kharisma\n");
b++;
}while(b<=a);
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=1;
do{
areahasil1.append(b+"0.Kharisma\n");
b++;
}while(b<=a);
}
Source code button "Proses Perulangan 2", sebagai Berikut :
private void bProses2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
do{
areahasil2.append(b+"\n");
b--;
}while(b>0);
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
do{
areahasil2.append(b+"\n");
b--;
}while(b>0);
}
Source code button " Proses Perulangan 3", sebagai berikut :
private void bProses3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
do{
areahasil3.append(b+"\n");
b=b-3;
}while(b>=0);
}
// TODO add your handling code here:
int a,b;
a=Integer.parseInt(eBil.getText());
b=a;
do{
areahasil3.append(b+"\n");
b=b-3;
}while(b>=0);
}
Source code untuk button "Proses Perulangan 4", sebagai berikut:
private void bProses4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int a,b;
int jum=0;
b=1;
a=Integer.parseInt(eBil.getText());
do{
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
b++;
}while(b<=a);
}
// TODO add your handling code here:
int a,b;
int jum=0;
b=1;
a=Integer.parseInt(eBil.getText());
do{
jum=jum+b;
if(b<a){
areahasil4.append(b+"+");
}else{
areahasil4.append(b+"="+jum);
}
b++;
}while(b<=a);
}
Source code untuk button Batal nya yaitu :
private void bBatalActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
// TODO add your handling code here:
eBil.setText("");
areahasil1.setText("");
areahasil2.setText("");
areahasil3.setText("");
areahasil4.setText("");
eBil.requestFocus();
}
Dan source code untuk button Keluar :
private void bKeluarActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
// TODO add your handling code here:
dispose();
}
Jika semua program telah selesai, maka lakukan Clean and Build Project dan Run File. Maka akan tampil dari ketiga proses perulangan diatas adalah sebagai berikut :
![]() |
| Gambar 7,8,9.2 Hasil Run File |
Contoh, masukkan jumlah perulangan seperti pada gambar berikut :
![]() |
| Gambar 7,8,9.3 Masukkan Jumlah Perulangan |
Jika button "Proses Perulangan 1" diklik, maka akan tampil seperti berikut :
![]() |
| Gambar 7,8,9.4 Button "Proses Perulangan 1" |
Jika button "Proses Perulangan 2" diklik, maka akan tampil seperti :
![]() |
| Gambar 7,8,9.5 Button "Proses Perulangan 2" |
Jika button "Proses Perulangan 3" diklik, maka akan menampilkan :
![]() |
| Gambar 7,8,9.6 Button "Proses Perulangan 3" |
Dan jika button "Proses Perulangan 4" diklik, maka akan tampil seperti pada gambar dibawah ini :
![]() |
| Gambar 7,8,9.7 Button "Proses Perulangan 4" |
Jika button Batal diklik, data akan hilang dan bersih seperti semula seperti pada gambar dibawah ini :
![]() |
| Gambar 7,8,9.8 Button Batal |
Jika button Keluar diklik, maka akan keluar dari Form tersebut.








Tidak ada komentar:
Posting Komentar