I have to create a java word game to guess words.
the question asks:
Using an appropriate screen layout, design, implement and test a java swing application to produce a game called Guess the word.
When the game begins, the program should choose the word at random from a bank of words.
The user is invited to enter a guess and have it checked. Any letters that are guessed correctly should be indicated to the user.
I am not sure how to code this to make the program choose a word at random from the Words Array. Any help would be greatly appreciated.
Here is my code so far:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Scanner;
public class WordGuessgame
{
JFrame frame;
JPanel panel;
JLabel label;
JTextArea word;
String [] GuessWords;
JButton checkletter;
JButton giveup;
String wordSoFar = "", updatedWord = "";
String [] Words = { // Creating Array of words.
"Bank", "Assignment", "Dog", "Car", "House", "Network", "Programming", "Tea",
"JCreator", "Banbridge"};
char [] Letters = {'A', 'B','C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z'};
String [] Guesswords ={ "_ _ _ _ ", "_ _ _ _ _ _ _ _ _ _", "_ _ _", "_ _ _", "_ _ _ _ _", "_ _ _ _ _ _ _", "_ _ _ _ _ _ _ _ _ _ _",
"_ _ _", "_ _ _ _ _ _ _ _", "_ _ _ _ _ _ _ _ _"};
public static void main(String[]args)
{
WordGuessgame app = new WordGuessgame();
app.go();
}
public void go()
{
frame = new JFrame();
panel = new JPanel();
frame.getContentPane().add(BorderLayout.NORTH, panel);
frame.setVisible(true);
frame.setSize(800,800);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setLayout(new FlowLayout());
label = new JLabel(" Word Guessing Game");
panel.add(label);
checkletter = new JButton("Check");
panel.add(checkletter);
word = new JTextArea("");
panel.add(word);
giveup = new JButton("Give up!");
panel.add(giveup);
}
}










