0% found this document useful (0 votes)
22 views

Program Game Java Sederhana

The document contains source code for two buttons - a "putar" button and a "new game" button. The "putar" button code generates random numbers, checks for matching numbers, and updates the labels with the results. The "new game" button code resets the labels to their initial states to start a new game.

Uploaded by

Rizwal Hadi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Program Game Java Sederhana

The document contains source code for two buttons - a "putar" button and a "new game" button. The "putar" button code generates random numbers, checks for matching numbers, and updates the labels with the results. The "new game" button code resets the labels to their initial states to start a new game.

Uploaded by

Rizwal Hadi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Sourcode di buttom “putar”

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


// TODO add your handling code here:
int val1,val2,val3,val4,val5,val6,val7,val8;
Random rnd = new Random();
val1 = rnd.nextInt(9);
val2 = rnd.nextInt(9);
val3 = rnd.nextInt(9);
val4 = Integer.parseInt(jLabel6.getText());
val5 = 50;
val6 = 10;
val7 = 20;
val8 = 30;

jLabel2.setText(Integer.toString(val1));
jLabel3.setText(Integer.toString(val2));
jLabel5.setText(Integer.toString(val3));
jLabel6.setText(Integer.toString(val3));
if ((val1==7)&&(val2==7)&&(val3==7)) {
jLabel4.setText("Selamat anda mendapat jackpot");
jLabel6.setText(Integer.toString(val4 + val5));
}
else if((val1==val2)||(val1==val3)||(val2==val3)) {
jLabel4.setText("Selamat 2 angka sama!");
jLabel6.setText(Integer.toString(val4 + val7));

}
else if((val1==val2)&&(val1==val3)&&(val2==val3)) {
jLabel4.setText("Selamat 3 angka sama!");
jLabel6.setText(Integer.toString(val4 + val8));

}
else {
jLabel4.setText("cobalagi ya...!");
jLabel6.setText(Integer.toString(val4 - val6));

}
}

2.Sourcode di buttom “new game”

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


// TODO add your handling code here:
jLabel6.setText("100");
jLabel2.setText("0");
jLabel3.setText("0");
jLabel5.setText("0");
jLabel4.setText("Ayo Main!!");

}
3.Out put

You might also like