RSS

Game Java Random Angka – Runnable

03 Mei

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package utsdamg;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Random;
import javax.sound.sampled.*;
import javax.swing.*;

/**
*
* @author hafizh
*/
public class tes extends JFrame implements Runnable, KeyListener, ActionListener {

private utsdamg.Background bg;
int jawab = 0;
String pertanyaan = “”;
String nyawa = “”;
String jawaban = “”;
String score2=””;
String pesan=””;
int nyawa2=5;
int x = -50;
int y = 150;
int jalan=220;
int score=0;
int waktu=300;
Thread tr=new Thread(this);
JButton jb=new JButton();
AudioInputStream suara;

public tes(){
bg=new utsdamg.Background();
setSize(924,668);
setDefaultCloseOperation(EXIT_ON_CLOSE);

setUndecorated(true);
setLocationRelativeTo(null);
getContentPane().add(bg,java.awt.BorderLayout.CENTER);
setVisible(true);
setLayout(null);

random();
tr.start();

addKeyListener(this);

}
public void random() {
String angka[] = {“1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”};
String operator[] = {“*”, “+”, “-“};
Random ra = new Random();
int indexo = ra.nextInt(operator.length);
int index = ra.nextInt(angka.length);
int index2 = ra.nextInt(angka.length);
int angka1 = Integer.parseInt(angka[index]);
int angka2 = Integer.parseInt(angka[index2]);
String opr = operator[indexo];

if (opr.equalsIgnoreCase(“*”)) {
y+=25;
jawab = angka1 * angka2;
pertanyaan = String.valueOf(angka1) + ” * ” + String.valueOf(angka2);
} else if (opr.equalsIgnoreCase(“+”)) {
y+=50;
pertanyaan = String.valueOf(angka1) + ” + ” + String.valueOf(angka2);
jawab = angka1 + angka2;
} else if (opr.equalsIgnoreCase(“-“)) {
y=+70;
pertanyaan = String.valueOf(angka1) + ” – ” + String.valueOf(angka2);
jawab = angka1 – angka2;
}
}

@Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;

g2d.setFont(new Font(“Kristen ITC”, Font.PLAIN, 60));
g2d.setColor(Color.WHITE);
g2d.drawString(jawaban,570, 400);

g2d.setFont(new Font(“Kristen ITC”, Font.PLAIN, 40));
g2d.setColor(Color.getHSBColor(jalan,(float) 1*jalan, (float) 1*jalan));
g2d.drawString(pertanyaan,jalan, 140);

nyawa=String.valueOf(nyawa2);
g2d.setFont(new Font(“Kristen ITC”, Font.PLAIN, 70));
g2d.setColor(Color.WHITE);
g2d.drawString(nyawa,260, 310);

score2=String.valueOf(score);
g2d.setFont(new Font(“Kristen ITC”, Font.PLAIN, 70));
g2d.setColor(Color.getHSBColor(jalan,(float) 1*jalan*2, (float) 1*jalan*2));
g2d.drawString(score2,480, 310);

g2d.setFont(new Font(“Tempus Sans ITC”, Font.PLAIN, 20));
g2d.setColor(Color.WHITE);

Download source : https://www.dropbox.com/s/8xpj29cyueshmkz/source.txt

 
Tinggalkan komentar

Ditulis oleh pada 3 Mei 2012 in Java

 

Tag: , , , , , , , , , , ,

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

 
%d blogger menyukai ini: