Project Game Hangman – Java

Assalamualaikum sahabat whitecyber semua …

Kali ini kita mendapatkan project dari pelanggan kita untuk diminta membuat GAME dengan metode HANGMAN dengan menggunakan bahasa pemprograman JAVA. Whitecyber team kali ini akan sharing secara bertahap bagaimana mengembangkan Game tersebut dari GAME yang sederhana menjadi lebih menarik. Yuk ikuti …

Apa itu Hangman ?

Hangman adalah permainan tebak kata yang populer di mana pemain berusaha menyusun kata yang hilang dengan berspekulasi satu huruf pada satu waktu. Setelah sejumlah dugaan yang salah, permainan selesai dan pemain kalah. Permainan juga selesai ketika pemain secara akurat membedakan semua huruf dari kata yang hilang. Implementasi game ini di Java diberikan di bawah ini.

Memahami Permainan
 

Sebuah kata harus ditebak oleh pemain. Jadi, layar keluaran akan menampilkan jumlah garis yang mewakili huruf-huruf yang tersisa untuk ditebak. Kemudian pemain akan menebak sebuah huruf. Jika huruf tersebut ada pada kata tersebut maka program akan mengganti tanda hubung dengan huruf tersebut di setiap tempat kemunculannya. Jika huruf tersebut tidak ada dalam kata maka jumlah garis hidup akan berkurang (yang terdiri dari jumlah peluang yang terbatas). Pemain memenangkan permainan segera setelah semua huruf dari kata tersebut telah ditebak dengan benar.

Rencana permainan:

Pengguna harus mulai dengan menebak huruf yang paling sering muncul dalam kata yang merupakan huruf vokal ( a , e , i , o , u ). Selain huruf vokal, huruf lain yang paling umum digunakan adalah t , n , s , h , r , d dan l .

 

Implementasi permainan

Dalam program tersebut, telah dibuat Permainan Kelas yang di dalamnya dibuat daftar string yang terdiri dari kata-kata. Dalam daftar kata, satu kata akan dipilih secara acak menggunakan modul acak ( java.util.Random ) agar pengguna dapat menebak hurufnya. Setelah memilih kata, semua huruf dijadikan huruf besar menggunakan fungsi toUpperCase() dan kemudian huruf tersebut diganti dengan tanda hubung. Jumlah maksimal tebakan salah yang diperbolehkan dalam permainan adalah 5 , jika pengguna melampaui itu maka pengguna akan kalah dalam permainan. Dalam perulangan while saat pengguna mulai menebak huruf, tebakan yang benar akan menggantikan tanda hubung dengan huruf yang benar sedangkan tebakan yang salah akan menambah variabel penghitungan jumlah tebakan yang salah sebanyak 1 .

  • Kondisi pertama digunakan untuk memberi tahu pengguna tentang garis hidup yang tersisa ketika pengguna salah menebak huruf.
  • Kondisi kedua digunakan untuk memberi tahu pengguna bahwa huruf yang dimasukkan sudah dapat ditebak.
  • Syarat ketiga adalah memeriksa apakah huruf baru yang ditebak ada pada kata tersebut atau tidak, jika benar maka tanda hubung diganti dengan huruf yang benar tersebut.
  • Jika huruf tersebut tidak ada pada kata tersebut, maka garis hidup dikurangi 1.

Permainan berakhir jika salah satu syarat terpenuhi: 

  • Pengguna telah menebak seluruh kata dengan benar.
  • Jalur hidup pengguna telah selesai. 

Kali ini Whitecyber membuat SAMPLE terlebih dahulu dengan Game berupa CONSOLE. hasilnya adalah sebagai berikut :

.

 

.

Source Codenya adalah sebagai berikut :

.

====

..

// Program Java yang akan diimplementasikan
// Hangman game
import java.util.Scanner;
import java.util.Random;
class Game {
    static Scanner input;
    public static void hangman()
    {
        input = new Scanner(System.in);
        // array string yang berisi kata-kata
        String[] company = { “Maruti”, “Tata”, “Suzuki”,
                            “Ducati”, “Toyota” };
        System.out.println(
            ” Selamat Datang di Permainan Tebak Kata “);
        Random obj = new Random();
        int Ran_num = obj.nextInt(5);
        // mengambil input kata
        String word = (company[Ran_num]);
        word = word.toUpperCase();
        // Untuk menampilkan kata yang diberi garis bawah
        String word1 = word.replaceAll(“[A-Z]”, “_ “);
        // Mainkan permainannya
        System.out.println(“Ayo kita mainkan Gamenya”);
        startGame(word, word1);
    }
    public static void startGame(String word, String word1)
    {
        // jumlah tebakan
        int guess_ = 0;
        // jumlah tebakan yang salah
        int wrong = 0;
        // untuk setiap tebakan
        String guess;
        // menyimpan huruf yang ditebak
        char letter;
        // menyimpan jika huruf itu sudah di tebak
        // sudah menebak
        boolean guessescontainsguess;
        String guesses = “”;
        boolean guessinword;
        // perulangan while dimulai di sini
        while (wrong < 5 && word1.contains(“_”)) {
            System.out.println(word1 + “\n”);
            int temp = 5 – wrong;
            if (wrong != 0) {
                // untuk gambar 1
                System.out.println(“Anda masih “+temp
                                + ” punya tebakan.”);
            }
            System.out.print(“Tebakan Anda:”);
            // mengambil masukan tebakan
            guess = input.nextLine();
            // mengkonversi ke huruf besar
            // untuk perbandingan
            guess = guess.toUpperCase();
            // mendapat huruf pertama
            // seperti tebakan huruf
            letter = guess.charAt(0);
            guessescontainsguess
                = (guesses.indexOf(letter)) != -1;
            // menyimpan setiap huruf
            // menebak-nebak
            guesses += letter;
            // mengkonversi ke huruf besar untuk
            // perbandingan
            letter = Character.toUpperCase(letter);
            System.out.println();
            // jika huruf sudah dapat ditebak
            if (guessescontainsguess == true) {
                // sudah menebak hurufnya
                System.out.println(“Anda SUDAH menebaknya “
                                + letter + “. \n”);
            }
            // tebakan huruf ada di dalam kata
            guessinword = (word.indexOf(letter)) != -1;
            // jika pernyataan dimulai  
            if (guessinword == true) {
                // cetak surat itu
                System.out.println(
                    letter + ” hadir dalam kata tersebut.”);
                System.out.print(“\n”);
                // temukan posisi hurufnya
                // ganti tanda hubung dengan itu
                // surat pada posisi yang valid
                for (int position = 0;
                    position < word.length(); position++) {
                    // tebakan huruf sama dengan
                    // huruf pada posisi dalam kata
                    // dan word1 sebelumnya tidak
                    // punya surat itu
                    if (word.charAt(position) ==letter
                        && word1.charAt(position)
                            != letter) {
                        word1 = word1.replaceAll(“_ “, “_”);
                        String word2;
                        word2 = word1.substring(0, position)
                                +letter
                                +word1.substring(position
                                                + 1);
                        word2 = word2.replaceAll(“_”, “_ “);
                        word1 = word2;
                    }
                }
            }
            // pernyataan if berakhir, else if dimulai
            else {
                // mencetak
                // salah = salah + 1, lagipula
                // jawaban yang salah
                System.out.println(
                    letter
                    + ” tidak ada dalam kata tersebut.”);
                wrong++;
            }
            // tebak_ = tebak_ + 1, setelahnya
            // percobaan
            guess_++;
        } // sementara perulangan berakhir
        // jika jalur kehidupan selesai
        if (wrong == 5) {
            System.out.println(
                “ANDA KALAH!, batas maksimum tebakan salah tercapai.”);
        }
        else {
            // ketika diselesaikan
            System.out.print(
                “Kata tersebut adalah : “+word1
                + “\n Dimainkan dengan Baik, Anda berhasil!!”);
        }
    }
    public static void main(String[] args)
    {
        // mainkan permainan Hangman
        hangman();
    }
}

 
====

Download : here

.

Bila sudah sampai tahap ini berarti PERMAINAN INTI sudah berez …

Sekarang kita masuk ke Tahap Pemindahan GAME Menuju pembuatan DATABASE dan GUI – Graphical User Interface.

.

.

Membuat Rancangan DESAIN LOGIN.

.

.

Desain Input data Kamus Gamenya .

.

.

Desain Form User Interfacenya :

.

.

Sekarang kita Desain dan Uji Coba dengan User Interface Game dengan Variable-variable yang kita gunakan :

.

.

Sekarang setelah semua variable dari Game terpenuhi, kita membangun DESAIN GUI yang enak dipandang dan bisa digunakan oleh pengguna. Oleh sebab itu kita satukan entitas label yang bisa disatukan. kemudian kita hapus textfield yang tidak dipakai dan kita sederhanakan namun dengan fungsi tetap berjalan normal.

Berikut ini hasil dari GUI yang kita setting untuk kita uji coba terlebih dahulu di lapangan sebelum kita press release.

.

.

Sekarang kita akan kembangkan interface yang ada di game tersebut, yang pertama kita akan munculkan PEMENANG berdasarkan dari SKOR dan diurutkan dengan waktu TIMER.

.

.

Disitu kita bisa lihat JUARA 1 sampai terakhir yang otomatis sudah terurut dengan rapi.

.

.

Kita juga akan menambahkan JUMLAH HINT yang belum dipakai di LEVEL sebelumnya saat naik ke LEVEL Selanjutnya.

.

.

Sekarang tinggal kita selesaikan tahap akhir, yaitu merampungkan LEVEL 3.

.

.

.

SOURCE CODE

.

/*

 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license

 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template

 */

package form;

 

import java.util.Scanner; 

import java.util.Random;

import Koneksi.KoneksiDatabase;

import java.awt.Color;

import java.sql.*;

import javax.swing.JOptionPane;

import java.awt.event.KeyEvent;

import java.util.Timer;

import java.util.TimerTask;

 

/**

 *

 * @author GK3v

 */

public class MainGame extends javax.swing.JFrame { 

    /**

     * Creates new form FSetting

     */

    public Statement st;

    public ResultSet rs;

    Connection cn = KoneksiDatabase.BukaKoneksi();

    int jawab;

    static int interval;

    int hint;

    static Timer timer;

    

    public MainGame() {

        initComponents();

        setLocationRelativeTo(this);

    }

 

    /**

     * This method is called from within the constructor to initialize the form.

     * WARNING: Do NOT modify this code. The content of this method is always

     * regenerated by the Form Editor.

     */

    @SuppressWarnings(“unchecked”)

    

    private static final int setInterval() {

        if (interval == 1)

            timer.cancel();

            return –interval; 

    }

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

    private void initComponents() {

 

        jPanel1 = new javax.swing.JPanel();

        label6 = new java.awt.Label();

        textField2 = new java.awt.TextField();

        label15 = new java.awt.Label();

        textField11 = new java.awt.TextField();

        label7 = new java.awt.Label();

        textField4 = new java.awt.TextField();

        label2 = new java.awt.Label();

        textField1 = new java.awt.TextField();

        label8 = new java.awt.Label();

        textField10 = new java.awt.TextField();

        label10 = new java.awt.Label();

        textField5 = new java.awt.TextField();

        jPanel2 = new javax.swing.JPanel();

        label25 = new java.awt.Label();

        label26 = new java.awt.Label();

        label27 = new java.awt.Label();

        textField12 = new java.awt.TextField();

        label30 = new java.awt.Label();

        textField6 = new java.awt.TextField();

        label1 = new java.awt.Label();

        button1 = new java.awt.Button();

        button3 = new java.awt.Button();

        button4 = new java.awt.Button();

        jPanel3 = new javax.swing.JPanel();

        label4 = new java.awt.Label();

        label5 = new java.awt.Label();

        textField3 = new java.awt.TextField();

        button2 = new java.awt.Button();

        label16 = new java.awt.Label();

        label28 = new java.awt.Label();

        textField13 = new java.awt.TextField();

        label31 = new java.awt.Label();

        label32 = new java.awt.Label();

        label29 = new java.awt.Label();

        jPanel5 = new javax.swing.JPanel();

        label19 = new java.awt.Label();

        label20 = new java.awt.Label();

        jPanel6 = new javax.swing.JPanel();

        label24 = new java.awt.Label();

        jComboBox1 = new javax.swing.JComboBox<>();

        label12 = new java.awt.Label();

        textField7 = new java.awt.TextField();

        label14 = new java.awt.Label();

        textField9 = new java.awt.TextField();

        jMenuBar1 = new javax.swing.JMenuBar();

        jMenu1 = new javax.swing.JMenu();

        jMenu2 = new javax.swing.JMenu();

        jMenu3 = new javax.swing.JMenu();

        jMenu4 = new javax.swing.JMenu();

 

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

 

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

        jPanel1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createCompoundBorder(), null));

 

        label6.setText(“guess_”);

 

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

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

                textField2ActionPerformed(evt);

            }

        });

 

        label15.setText(“temp”);

 

        label7.setText(“wrong”);

 

        label2.setText(“guess”);

 

        label8.setText(“letter”);

 

        label10.setText(“guesses”);

 

        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(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(19, 19, 19)

                .addComponent(label15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(textField11, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(2, 2, 2)

                .addComponent(textField4, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(2, 2, 2)

                .addComponent(textField10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(1, 1, 1)

                .addComponent(textField5, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)

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

        );

        jPanel1Layout.setVerticalGroup(

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

            .addGroup(jPanel1Layout.createSequentialGroup()

                .addContainerGap()

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

                    .addComponent(textField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField11, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

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

        );

 

        jPanel2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

 

        label25.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label25.setText(“USERNAME :”);

 

        label26.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label26.setText(“Nama”);

 

        label27.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label27.setText(“SCORE :”);

 

        textField12.setText(“0”);

 

        label30.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label30.setText(“HINT :”);

 

        textField6.setText(“3”);

 

        label1.setAlignment(java.awt.Label.CENTER);

        label1.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label1.setText(“SELAMAT DATANG DI GAME”);

 

        button1.setLabel(“START”);

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

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

                button1ActionPerformed(evt);

            }

        });

 

        button3.setLabel(“HINT”);

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

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

                button3ActionPerformed(evt);

            }

        });

 

        button4.setLabel(“SAVE”);

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

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

                button4ActionPerformed(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)

                    .addComponent(label1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                    .addGroup(jPanel2Layout.createSequentialGroup()

                        .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                        .addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                        .addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(32, 32, 32)

                        .addComponent(label25, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(1, 1, 1)

                        .addComponent(label26, javax.swing.GroupLayout.DEFAULT_SIZE, 96, Short.MAX_VALUE)

                        .addGap(19, 19, 19)

                        .addComponent(label27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(1, 1, 1)

                        .addComponent(textField12, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                        .addComponent(label30, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(1, 1, 1)

                        .addComponent(textField6, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)))

                .addContainerGap())

        );

        jPanel2Layout.setVerticalGroup(

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

            .addGroup(jPanel2Layout.createSequentialGroup()

                .addGap(3, 3, 3)

                .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

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

                    .addComponent(textField12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label25, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label30, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(button3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(button4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

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

        );

 

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

 

        label4.setAlignment(java.awt.Label.CENTER);

        label4.setFont(new java.awt.Font(“Dialog”, 1, 48)); // NOI18N

        label4.setText(“TEBAK KATA”);

 

        label5.setFont(new java.awt.Font(“Dialog”, 0, 18)); // NOI18N

        label5.setText(“Tebakan Anda :”);

 

        textField3.setFont(new java.awt.Font(“Dialog”, 0, 18)); // NOI18N

 

        button2.setLabel(“Tebak”);

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

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

                button2ActionPerformed(evt);

            }

        });

 

        label16.setAlignment(java.awt.Label.CENTER);

        label16.setForeground(new java.awt.Color(51, 0, 153));

        label16.setText(“Klik START untuk mulai !”);

 

        label28.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label28.setText(“KATA :”);

 

        textField13.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        textField13.setName(“”); // NOI18N

        textField13.setText(“0”);

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

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

                textField13ActionPerformed(evt);

            }

        });

 

        label31.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label31.setForeground(new java.awt.Color(255, 0, 0));

        label31.setText(“WAKTU”);

 

        label32.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label32.setText(“TIME :”);

 

        label29.setAlignment(java.awt.Label.CENTER);

        label29.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        label29.setFont(new java.awt.Font(“Dialog”, 1, 14)); // NOI18N

        label29.setText(“LEVEL 1”);

 

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);

        jPanel3.setLayout(jPanel3Layout);

        jPanel3Layout.setHorizontalGroup(

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

            .addComponent(label4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addComponent(label29, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addComponent(label16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addGroup(jPanel3Layout.createSequentialGroup()

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

                    .addGroup(jPanel3Layout.createSequentialGroup()

                        .addContainerGap()

                        .addComponent(label28, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(1, 1, 1)

                        .addComponent(textField13, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                        .addComponent(label32, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                        .addGap(2, 2, 2)

                        .addComponent(label31, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

                    .addGroup(jPanel3Layout.createSequentialGroup()

                        .addGap(208, 208, 208)

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

                            .addGroup(jPanel3Layout.createSequentialGroup()

                                .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                                .addComponent(textField3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))

                            .addComponent(button2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))))

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

        );

        jPanel3Layout.setVerticalGroup(

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

            .addGroup(jPanel3Layout.createSequentialGroup()

                .addContainerGap()

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

                    .addComponent(label31, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label28, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(label32, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

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

                .addComponent(label29, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(37, 37, 37)

                .addComponent(label4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(70, 70, 70)

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

                    .addComponent(label5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                    .addComponent(textField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

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

                .addComponent(button2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap(18, Short.MAX_VALUE))

        );

 

        label16.getAccessibleContext().setAccessibleDescription(“”);

 

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

        jPanel5.setBorder(new javax.swing.border.MatteBorder(null));

 

        label19.setAlignment(java.awt.Label.CENTER);

        label19.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label19.setText(“permaian cek kata”);

 

        label20.setAlignment(java.awt.Label.CENTER);

        label20.setText(“Silahkan masukkan 1 huruf”);

 

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);

        jPanel5.setLayout(jPanel5Layout);

        jPanel5Layout.setHorizontalGroup(

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

            .addComponent(label20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

            .addComponent(label19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

        );

        jPanel5Layout.setVerticalGroup(

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

            .addGroup(jPanel5Layout.createSequentialGroup()

                .addComponent(label20, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addGap(1, 1, 1)

                .addComponent(label19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

        );

 

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

        jPanel6.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

 

        label24.setText(“Kategori”);

 

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { “Buah”, “Perkerjaan”, “Binatang” }));

 

        label12.setText(“keyword”);

 

        label14.setFont(new java.awt.Font(“Dialog”, 1, 12)); // NOI18N

        label14.setText(“Jawaban”);

 

        textField9.setBackground(new java.awt.Color(242, 242, 242));

 

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);

        jPanel6.setLayout(jPanel6Layout);

        jPanel6Layout.setHorizontalGroup(

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

            .addGroup(jPanel6Layout.createSequentialGroup()

                .addContainerGap()

                .addComponent(label24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                .addComponent(label12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(textField7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(label14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(textField9, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

        jPanel6Layout.setVerticalGroup(

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

            .addGroup(jPanel6Layout.createSequentialGroup()

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

                    .addGroup(jPanel6Layout.createSequentialGroup()

                        .addGap(12, 12, 12)

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

                            .addComponent(label24, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))

                    .addGroup(jPanel6Layout.createSequentialGroup()

                        .addContainerGap()

                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)

                            .addComponent(textField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(label12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(label14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

                            .addComponent(textField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))

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

        );

 

        jMenu1.setText(“Home”);

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

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

                jMenu1MouseClicked(evt);

            }

        });

        jMenuBar1.add(jMenu1);

 

        jMenu2.setText(“Dictionary”);

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

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

                jMenu2MouseClicked(evt);

            }

        });

        jMenuBar1.add(jMenu2);

 

        jMenu3.setText(“User”);

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

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

                jMenu3MouseClicked(evt);

            }

        });

        jMenuBar1.add(jMenu3);

 

        jMenu4.setText(“Peraturan”);

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

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

                jMenu4MouseClicked(evt);

            }

        });

        jMenuBar1.add(jMenu4);

 

        setJMenuBar(jMenuBar1);

 

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

        getContentPane().setLayout(layout);

        layout.setHorizontalGroup(

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

            .addGroup(layout.createSequentialGroup()

                .addGap(15, 15, 15)

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

                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

                    .addComponent(jPanel5, 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(14, Short.MAX_VALUE))

        );

        layout.setVerticalGroup(

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

            .addGroup(layout.createSequentialGroup()

                .addGap(11, 11, 11)

                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

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

                .addComponent(jPanel6, 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)

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

                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)

                .addContainerGap())

        );

 

        pack();

    }// </editor-fold>                        

 

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

        // TODO add your handling code here:

        //Memunculkan Kata Kunci

        textField7.setVisible(false);

        textField9.setVisible(false);

        jComboBox1.setVisible(false);

        label24.setVisible(false);

        label12.setVisible(false);

        label14.setVisible(false);

        // Setting Waktu

        int waktu = 180; // 3 menit

        label31.setText(Integer.toString(waktu));

        // Menambah Nomor Pertanyaan

        // Pertanyaan + 0

        int nopertanyaan = Integer.valueOf(textField13.getText()); 

        nopertanyaan = nopertanyaan + 1;

        textField13.setText(Integer.toString(nopertanyaan));

        if (nopertanyaan == 6) {

            label29.setText(“LEVEL 2”);

            waktu = 150; // 2.5 menit

            label31.setText(Integer.toString(waktu));

            // Mengganti warna background

            jPanel3.setBackground(Color.PINK);

            label4.setBackground(Color.PINK);

            jPanel5.setBackground(Color.PINK);

            // Menambah Hint

            hint = Integer.valueOf(textField6.getText());

            hint = hint + 2;

            textField6.setText(String.valueOf(hint));

        } else if (nopertanyaan == 16) {

            label29.setText(“LEVEL 3”);

            waktu = 120; // 2.5 menit

            label31.setText(Integer.toString(waktu));

            jPanel3.setBackground(Color.YELLOW);

            label4.setBackground(Color.YELLOW);

            jPanel5.setBackground(Color.YELLOW);

            // Menambah Hint

            hint = Integer.valueOf(textField6.getText());

            hint = hint + 2;

            textField6.setText(String.valueOf(hint));

        } else if (nopertanyaan == 31 ) {

            JOptionPane.showMessageDialog(null, “PERMAINAN SELESAI, TUTUP PROGRAM !”);

            //exit keluar dari program

            System.exit(0);

        }

        

        // Memulai Waktu

        String secs = label31.getText();

        int delay = 1000;

        int period = 1000;

        timer = new Timer();

        interval = Integer.parseInt(secs);

        label31.setText(secs);

        timer.scheduleAtFixedRate(new TimerTask() {            

        public void run() {

            label31.setText(String.valueOf(setInterval()));

        }        

        }

        , delay, period);

        

        

        // Database Kata

        // Menentukan 1 Kata yang diambil secara acak dari SQL

        if (textField7.getText() != “”) {

            //int jawab = JOptionPane.showConfirmDialog(null, “Mau bermain dengan kategori = “+jComboBox1.getSelectedItem()+” ?”, “Konfirmasi”, JOptionPane.YES_NO_OPTION);

            try {

                st = cn.createStatement();

                rs = st.executeQuery(“SELECT * FROM kamus WHERE kategori='”+jComboBox1.getSelectedItem()+”‘ ORDER BY RAND() LIMIT 1”);            

                while (rs.next()) {

                    textField7.setText(rs.getString(“kata”));

                    JOptionPane.showMessageDialog(null, “Siap Tebak 1 Kata “+jComboBox1.getSelectedItem()+” ini ?”); 

                    rs = st.executeQuery(“SELECT * FROM kamus”); 

                    break;

                }            

            } catch (Exception e) {

                JOptionPane.showMessageDialog(null,”SQLnya ndak jalan”);

            }

        } 

        

        String word = textField7.getText(); 

        // Merubahnya menjadi huruf besar

        word = word.toUpperCase();  

        textField9.setText(word);

        // Untuk menampilkan kata yang diberi garis bawah 

        String word1 = word.replaceAll(“[A-Z]”, “_ “);

        // Menampilkannya di layar quis

        label4.setText(word1);

        // Mengajak Bermain

        label16.setText(“ayo kita mainkan gamenya”);

        // jumlah tebakan

int guess_ = 0;

        textField2.setText(Integer.toString(guess_));

// jumlah tebakan yang salah

int wrong = 0;

        textField4.setText(Integer.toString(wrong));

        // untuk setiap tebakan textField1

String guess; 

        textField1.setText(“guess”);

        // menyimpan huruf yang ditebak

char letter;

        textField10.setText(“letter”);

        // menyimpan jika huruf itu sudah di tebak

        // sudah menebak

        String guesses = “”;

        textField5.setText(“”);

        int temp = 5;

        textField11.setText(Integer.toString(temp));

        

    }                                       

 

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

                // Memasukkan variabelnya dulu

                int wrong = Integer.valueOf(textField4.getText()); 

                String word1 = label4.getText();                

                while (wrong < 5 && word1.contains(“_”)) { 

                    //label18.setText(word1);

                    textField4.setText(String.valueOf(wrong));

                    int temp = 5 – wrong;

                    if (wrong > 0) { 

        // untuk gambar 1

label19.setText(“Anda masih ” + temp + ” kesempatan.”);

                                textField11.setText(Integer.toString(temp));

                    

                    // mengambil masukan tebakan

String guess = textField3.getText();

                        textField1.setText(guess);

                        // mengkonversi ke huruf besar untuk perbangingan

                        guess = guess.toUpperCase();

                        textField1.setText(guess);

                        //mendapatkan huruf pertama seperti tebakan huruf

                        char letter = guess.charAt(0);

                        textField10.setText(String.valueOf(letter));

                        String guesses = textField5.getText();

                        boolean guessescontainsguess = (guesses.indexOf(letter)) != -1; 

                        // menyimpan setiap huruf yang ditebak tebak

                        guesses += letter;

                        textField5.setText(guesses);

                        // jika huruf sudah dapat ditebak 

if (guessescontainsguess == true) {

// sudah menebak hurufnya

label19.setText(“Anda SUDAH menebaknya ” + letter + “.”); 

}

                        // tebakan huruf ada di dalam kata

                        String word = textField9.getText();

                        boolean guessinword = (word.indexOf(letter)) != -1;

                        // jika pernyataan dimulai

if (guessinword == true) {

                                // cetak huruf itu

label20.setText(letter + ” ada dalam kata tersebut.”);

                                // temukan posisi yang tepat lalu ganti dashes tersebut dengan huruf letter tersebut

                                for (int position = 0; position < word.length(); position++) {

                                    // tebakan huruf sama dengan

                                    // huruf pada posisi dalam kata

                                    // dan word1 sebelumnya tidak

                                    // punya surat itu

                                    if (word.charAt(position) == letter && word1.charAt(position) != letter) { 

word1 = word1.replaceAll(“_ “, “_”); 

String word2; 

word2 = word1.substring(0, position) + letter + word1.substring(position + 1); 

word2 = word2.replaceAll(“_”, “_ “); 

word1 = word2;

                                                // mencetak word1

                                                label4.setText(word1);

                                    } 

                                } 

                        } else {

                            // mencetak

                            // salah = salah + 1, lagipula jawaban salah

                            label20.setText( letter + ” tidak ada dalam kata tersebut.”);

                            wrong++;

                            String wrong2 = String.valueOf(wrong); 

                            textField4.setText(wrong2);

                            int temp2 = 5 – wrong;

                            String temp22 = String.valueOf(temp2); 

                            textField11.setText(temp22);

                        } 

                        

                        // tebak_ = tebak_ + 1, setelahnya

// percobaan

                        int guess_ = Integer.valueOf(textField2.getText());

guess_++; 

                        String guess_2 = String.valueOf(guess_);

                        textField2.setText(guess_2);

                        

                // jika jalur kehidupan selesai

                if (wrong == 5) { 

                    label16.setText( “ANDA KALAH!, batas maksimum tebakan salah tercapai.”); 

                    // Skor + 0

                    int skor = Integer.valueOf(textField12.getText()); 

                    skor = skor + 0;

                    textField12.setText(Integer.toString(skor));

                } else if (word1.contains(“_”)) { 

// ketika diselesaikan 

                    label16.setText( “Lanjut Tebak Lagi!”); 

                } else {

                    label16.setText( “Kata tersebut adalah : ” + textField9.getText() + “\n, Anda berhasil!!”);

                    // Skor + 10

                    int skor = Integer.valueOf(textField12.getText()); 

                    skor = skor + 10;

                    textField12.setText(Integer.toString(skor));

                    int batasjumlahpertanyaan = Integer.valueOf(textField13.getText());

                    if (( batasjumlahpertanyaan == 5) || (batasjumlahpertanyaan == 15) || (batasjumlahpertanyaan == 30) ) {

                        timer.cancel();

                        JOptionPane.showMessageDialog(null, “NAIK LEVEL SELANJUTNYA!”);

                    }    

                    

                }

                break;

                    

                }

    }                                       

 

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

        // TODO add your handling code here:

        label4.setText(“menu home”);

    }                                   

 

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

        // TODO add your handling code here:

        FSetting log2 = new FSetting();

        log2.setVisible(true);

    }                                   

 

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

        // TODO add your handling code here:

        FUser log3 = new FUser();

        log3.setVisible(true);

    }                                   

 

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

        // TODO add your handling code here:

    }                                           

 

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

        // TODO add your handling code here:

    }                                          

 

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

        // TODO add your handling code here:

        hint = Integer.valueOf(textField6.getText());

        if (hint > 0) {

            hint = hint – 1;

            textField6.setText(String.valueOf(hint));

            

            //Memunculkan Kata Kunci

            textField7.setVisible(true);

            textField9.setVisible(true);

            jComboBox1.setVisible(true);

            label24.setVisible(true);

            label12.setVisible(true);

            label14.setVisible(true);    

        } else {

            JOptionPane.showMessageDialog(null, “Bantuan Hint Sudah Habis”);

        }

    }                                       

 

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

        // TODO add your handling code here:

        

            try {

            st = cn.createStatement();

            if (label26.getText().equals(“”) && textField12.getText().equals(“”)){

               JOptionPane.showMessageDialog(null, “Data Tidak Boleh Kosong”, “Validasi Data”, JOptionPane.INFORMATION_MESSAGE);

               return;

            }

            

            if (button4.getLabel() == “SAVE”) {

                String cek = “SELECT * FROM pengguna WHERE user = ‘” + label26.getText() + “‘”;

                rs = st.executeQuery(cek);

                if ( rs.next()) {

                    JOptionPane.showMessageDialog(null, “Ups… User ini sudah ada”);

                    String update = “UPDATE pengguna SET user = ‘” + label26.getText() + “‘, skor = ‘” + textField12.getText() + “‘, timer = ‘” + label31.getText() + “‘ WHERE user = ‘” + label26.getText() + “‘”;

                    st.executeUpdate(update);

                    JOptionPane.showMessageDialog(null, “Data Skor dan Waktu Berhasil Diupdate”);

                } else {

                    String sql = “INSERT INTO pengguna VALUES (‘” + label26.getText() + “‘,'” + textField12.getText() + “‘,'” + label31.getText() + “‘)”;

                    st.executeUpdate(sql);

                    JOptionPane.showMessageDialog(null, “Skor Berhasil Disimpan”);

                }

            } 

            

        } catch (Exception e) {

            

        }

        

        //exit

        //System.exit(0);

    }                                       

 

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

        // TODO add your handling code here:

        FPeraturan log5 = new FPeraturan();

        log5.setVisible(true);

    }                                   

 

    /**

     * @param args the command line arguments

     */

    public static void main(String args[]) {

        /* Set the Nimbus look and feel */

        //<editor-fold defaultstate=”collapsed” desc=” Look and feel setting code (optional) “>

        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 

         */

        try {

            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {

                if (“Nimbus”.equals(info.getName())) {

                    javax.swing.UIManager.setLookAndFeel(info.getClassName());

                    break;

                }

            }

        } catch (ClassNotFoundException ex) {

            java.util.logging.Logger.getLogger(MainGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (InstantiationException ex) {

            java.util.logging.Logger.getLogger(MainGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (IllegalAccessException ex) {

            java.util.logging.Logger.getLogger(MainGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        } catch (javax.swing.UnsupportedLookAndFeelException ex) {

            java.util.logging.Logger.getLogger(MainGame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);

        }

        //</editor-fold>

 

        /* Create and display the form */

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

            public void run() {

                new MainGame().setVisible(true);

            }

        });

    }

 

    // Variables declaration – do not modify                     

    private java.awt.Button button1;

    private java.awt.Button button2;

    private java.awt.Button button3;

    private java.awt.Button button4;

    public javax.swing.JComboBox<String> jComboBox1;

    private javax.swing.JMenu jMenu1;

    private javax.swing.JMenu jMenu2;

    private javax.swing.JMenu jMenu3;

    private javax.swing.JMenu jMenu4;

    private javax.swing.JMenuBar jMenuBar1;

    private javax.swing.JPanel jPanel1;

    private javax.swing.JPanel jPanel2;

    private javax.swing.JPanel jPanel3;

    private javax.swing.JPanel jPanel5;

    private javax.swing.JPanel jPanel6;

    private java.awt.Label label1;

    public java.awt.Label label10;

    public java.awt.Label label12;

    public java.awt.Label label14;

    public java.awt.Label label15;

    private java.awt.Label label16;

    private java.awt.Label label19;

    public java.awt.Label label2;

    private java.awt.Label label20;

    public java.awt.Label label24;

    private java.awt.Label label25;

    public java.awt.Label label26;

    private java.awt.Label label27;

    private java.awt.Label label28;

    private java.awt.Label label29;

    private java.awt.Label label30;

    private java.awt.Label label31;

    private java.awt.Label label32;

    public java.awt.Label label4;

    private java.awt.Label label5;

    public java.awt.Label label6;

    public java.awt.Label label7;

    public java.awt.Label label8;

    public java.awt.TextField textField1;

    public java.awt.TextField textField10;

    public java.awt.TextField textField11;

    private java.awt.TextField textField12;

    private java.awt.TextField textField13;

    public java.awt.TextField textField2;

    private java.awt.TextField textField3;

    public java.awt.TextField textField4;

    public java.awt.TextField textField5;

    private java.awt.TextField textField6;

    public java.awt.TextField textField7;

    public java.awt.TextField textField9;

    // End of variables declaration                   

}

 

.

Leave a Reply

Your email address will not be published. Required fields are marked *