Java - Guess The Word Game Source Code

How To Make Guess The Word Game Project Using NetBeans

Java Guess The Word Game Source Code


In this Java Tutorial we will see How to Make a Simple Word Guessing Game App In Java NetBeans
In This Java NetBeans Game Project We Will Use Using Jframe JPanels, JButtons and Jlabels .





Project Source Code:

     // array of words
    String[] words = {"driver","signature","history", "response","president","highway", 
                      "computer", "appartment", "forest", "chocolat", "lawyer"};
    int index = -1;
    
    Border panel_border = BorderFactory.createMatteBorder(2, 2, 2, 2, Color.black);
    
    public Guess_Word_Game() {
        initComponents();
        
        this.setLocationRelativeTo(null);
        
        jPanel1.setBorder(panel_border);
        
        displayWord();
        
        jButton_Next_.setEnabled(false);
    }
    
   
    // create a function to display the word
    public void displayWord()
    {
        // default text
        if(index == -1)
        {
            jLabel_Word.setText("--Word--");
            jTextField_Guess.setText("--Guess--");
        }
        else
        {
            // get random position
            int pos1 = (int) (Math.random() * words[index].length());
            int pos2 = (int) (Math.random() * words[index].length());
            int pos3 = (int) (Math.random() * words[index].length());
            
            // set '_' at random positions
            StringBuilder newtext = new StringBuilder(words[index]);
            newtext.setCharAt(pos1, '_');
            newtext.setCharAt(pos2, '_');
            newtext.setCharAt(pos3, '_');
            
            // set text to the jlabel
            jLabel_Word.setText(newtext.toString());
        }
    }
    
    // create a function to check if the user guessed the correct word
    public void checkWord()
    {
        // if the guess is correct
        if(jTextField_Guess.getText().equals(words[index]))
        {
            jLabel_Result.setText("Correct");
            jLabel_Result.setBackground(Color.green);
        }
        // if not
        else
        {
            jLabel_Result.setText("Wrong");
            jLabel_Result.setBackground(Color.red);
        }
        // if it's the last word in the list
        if(index == words.length - 1)
        {
            jButton_Next_.setEnabled(false);
            jButton_Start_.setEnabled(true);
        }
        jTextField_Guess.setText("");
    }
    
     // label to close the form
    private void jLabel_Close_MouseClicked(java.awt.event.MouseEvent evt) {                                           
        // close the form
        System.exit(0);
    }                                          

    // button start / restart the game
    private void jButton_Start_ActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // start or restart the game
        index = 0;
        jTextField_Guess.setText("");
        jButton_Next_.setEnabled(true);
        jButton_Start_.setEnabled(false);
        jLabel_Result.setText("Result");
        jLabel_Result.setBackground(new java.awt.Color(102, 102, 102));
        displayWord(); 
    }                                              

    // button next
    private void jButton_Next_ActionPerformed(java.awt.event.ActionEvent evt) {                                              
        // check the word / display the next word
        checkWord();
        if(index < words.length - 1)
        {
           index++;
           displayWord(); 
        }
    }                                             
                                          



////// OUTPUT : 

Guess The Word Game Source Code In Java 1

Guess The Word Game Source Code In Java 2

Guess The Word Game Source Code In Java 3

Guess The Word Game Source Code In Java 4

Guess The Word Game Source Code In Java 5





download the source code



More Java Projects:





VB.Net Library Management System Source Code

Library System Project Source Code Using Visual Basic .Net And MySQL Database

VB.Net Library Management System Source Code


in this vb.net project tutorial serie we will see how to make a library management system using windowForm in visual basic .net programming language and mysql database.

goals of this project:
- give students / curious persons an example so they can learn from it.
- helping people create their first project. 
- sharing knowledge with others.

tools:
- visual basic .net programming language.
- microsoft visual studio express 2013.
- mysql database.
- phpmyadmin.
- xampp server.
- pixabay.com ( website to get free images ).
- canva.com ( to create the book covers )

Watch This Full Demo



if you want the source code click on the download button below


1 - The Login & Dashboard Form

the login form will allow the Users to login into the library system application Dashboard Form.


VB.Net Library Management System Login Form


the login and the dashboard forms will be displayed at the same time.
the dashboard form will be disabled until the user login succussfuly.


VB.Net Library Management System Dashboard Form


if the user is a simple user, he can't access to the circulation and the users section.


VB.Net Library Management System Menu


if the user is an admin, he can't access the users section.


VB.Net Library Management System Admin Menu


if the user is an owner.


VB.Net Library Management System Owner Menu


and as you can see the dashboard form consist of 3 parts:
1 - show some data analytics.
VB.Net Library Management System Analytics


2 - show a menu in the left-bar.
VB.Net Library Management System Left-Bar


3 - show the latest books & Members in the bottom.

VB.Net Library Management System New Books

VB.Net Library Management System New Members


2 - The Library System - Genres Form

- this form allow the users to add, edit remove books genre, and display all the genres in a datagridview.

VB.Net Library Management System Genres Form



3 - The Library System - Manage Authors


here the user can add a new author to the system. view all authors in a datagridview, and how many are there
- edit, remove the selected author from the datagridview.
- export the authors to a text file.

VB.Net Library Management System Authors Form


- if you want to see a selected author books, just select one from the datagridview and click the "Show Author Books" button.

VB.Net Library Management System Author's Books Form


4 - The Library System - Manage Books


this form is where you can manage the library books.
this form has multiple pages using tabControl.

page 1 - add a new book

VB.Net Library Management System Books Form

the button "select author" will show a form with all the authors in it to allow the user to select from it
( you need to douple click on the datagridview to select the author, the form will automaticaly close ).

VB.Net Library Management System Authors List Form


page 2 - edit a book

you can search the book you want to edit by id or isbn.

VB.Net Library Management System Edit Book Form


page 3 - books list

- in this page you can see all books, search a book by title.
- export books list to a text file.
- select a book and to edit or the delete page ( the selected book data will be displayed )
VB.Net Library Management System Books List Form


page 4 - remove book

this a simple page where the user can easlly remove a book by id.

VB.Net Library Management System Delete Book Form



5 - The Library System - Manage Members


in this form you can:
- add a new member to the system.
- edit the selected  member from the datagridview.
- delete the selected  member from the datagridview.
- export members to a text file


VB.Net Library Management System Members Form


6 - The Library System - Circulation Form

ISSUE BOOK: in this page you can issue a book to a specific member for a specific date.


VB.Net Library Management System Issue a Book Form


to select a book enter the book id and click "search book".
if this book id exist you will see the book title under the book id field. 
if this book is available ( by counting the quantity and other stuff  ) you will see YES if not you will see NO
the same is for the member, enter the member id > click search > you will see the member full name


Issue a Book Form


when you click on the book title an info card will show up.

Book Card Form


the same for the member, when you click on the member fullname an info card will show up.


Member Card Form


CIRCULATION LIST: in this page you can see all the circulations.

VB.Net Library Management System Book Circulation List Form



RETURN BOOK: in this page you can return a book or set it to lost, or remove a circulation.


VB.Net Library Management System Return Book Form


7 - The Library System - Manage Users Form

in this form you can manage the users.
this form contains:
1 - table with all users:
2 - a button to add a new user.
3 - a button to edit the selected user.
4 - a button to remove the selected user.
5 - a button to clear all textboxes

VB.Net Library Management System Users Form





if you want the source code click on the download button below