Hangman game

i need help creating a hangman game with a predefined array of words for a java assignment here is my code so far
input Textfield 1 "for inputing word letters"
int alltrys = 6; "allow 6 incorrect"
int nowrong =0;
char guess;
int guessnumbers;
boolean badGuess;
String[] words;
public void init (){
     word = newString(20); "this is going to be my array of predefined words"
          word(0) = "cardiff";
          word(1) = "bluebirds";
          word(2) = "ccfc";
          word(3) = "goal";
          word(4) = "alexander";
          word(5) = "jones";
          word(6) = "hamman";
          word(7) = "ridsdale";
          word(8) = "ninianpark";
          word(9) = "bluearmy";
          word(10) = "grandstand";
          word(11) = "cantonstand";
          word(12) = "grangeend";
          word(13) = "bobbank";
          word(14) = "wales";
          word(15) = "city";
          word(16) = "penalty";
          word(17) = "shoots";
          word(18) = "chopra";
          word(19) = "ayatollah";
               int w = rand.nextInt(20);
               int randomNumber I = Math.random()*word.length);
               for (int stringIndex = 0; stringIndex < word(i),length();stringIndex ++)
               char.currrentCharacter
dont know if some is even right but am reccomended to also use
drawString()
               drawOval()
               drawLine()
               TextField()
Button()
i am only new to java so really need help also using textpad to do java

well id like to see how good you are after just four
weeks after being taught by some ****** who dont know
how to do his job properlyYeah, blame your teacher. It couldn't possibly be your own fault.

Similar Messages

  • Console Hangman game HELP!!!

    I have to construct a hangman game, and am having some trouble with showing the letters of the word that is guess. Also, I cannot figure out where to put
    public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
    in my code to make it case insensitive. And my other big problem is that I cannot get the game to exit once the player guesses then enitre word correctly. Any suggestions will help.
    import java.util.*;
    import java.io.*;
    public class hangman
         public static void main(String [] args) throws IOException
              //     public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
              int maxTries = 7;
              int wordLength;
              boolean solved;
              StringBuffer guessedLetters = new StringBuffer();
              //the fileScan gets the first word for the game
              Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
              String secretWord = fileScan.next();
              //Creates a StringBuffer for the viewing of the letters guessed
              StringBuffer word = new StringBuffer();
              for(int i = 0; i <= secretWord.length(); i++)
              word.append("_");
              System.out.println("Welcome to the game of HANGMAN!!!!");
              System.out.println("You will have 7 chances to guess what the word is.");
              //     System.out.println("Your word is " + wordLength + " letters long.");
                   String letter;
                   while(maxTries > 0 && (word.equals(secretWord)) == false)
                   System.out.println(word.equals(secretWord));
                   System.out.println("The letters that you have guessed are: " + guessedLetters);
                   System.out.println("The word so far is: " + word);
                   System.out.print("Please enter a letter to guess: ");
                   Scanner inScan = new Scanner(System.in);
                   letter = inScan.next();
                   guessedLetters.append(letter + " ");     
                   if(secretWord.indexOf(letter) != (-1))
                             int addedLetter = secretWord.indexOf(letter);
                             word.replace(addedLetter, addedLetter, letter);
                              word.setLength(secretWord.length());
                   else
                        maxTries--;
                   System.out.println("You have " + maxTries + " wrong guesses left.");
    }THANKS

    I have to construct a hangman game, and am having some trouble with showing the letters of the word that is guess. Also, I cannot figure out where to put
    public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
    in my code to make it case insensitive. And my other big problem is that I cannot get the game to exit once the player guesses then enitre word correctly. Any suggestions will help.
    import java.util.*;
    import java.io.*;
    public class hangman
         public static void main(String [] args) throws IOException
              //     public static final Comparator<secretWord> CASE_INSENSITIVE_ORDER;
              int maxTries = 7;
              int wordLength;
              boolean solved;
              StringBuffer guessedLetters = new StringBuffer();
              //the fileScan gets the first word for the game
              Scanner fileScan = new Scanner(new FileInputStream("words.txt"));
              String secretWord = fileScan.next();
              //Creates a StringBuffer for the viewing of the letters guessed
              StringBuffer word = new StringBuffer();
              for(int i = 0; i <= secretWord.length(); i++)
              word.append("_");
              System.out.println("Welcome to the game of HANGMAN!!!!");
              System.out.println("You will have 7 chances to guess what the word is.");
              //     System.out.println("Your word is " + wordLength + " letters long.");
                   String letter;
                   while(maxTries > 0 && (word.equals(secretWord)) == false)
                   System.out.println(word.equals(secretWord));
                   System.out.println("The letters that you have guessed are: " + guessedLetters);
                   System.out.println("The word so far is: " + word);
                   System.out.print("Please enter a letter to guess: ");
                   Scanner inScan = new Scanner(System.in);
                   letter = inScan.next();
                   guessedLetters.append(letter + " ");     
                   if(secretWord.indexOf(letter) != (-1))
                             int addedLetter = secretWord.indexOf(letter);
                             word.replace(addedLetter, addedLetter, letter);
                              word.setLength(secretWord.length());
                   else
                        maxTries--;
                   System.out.println("You have " + maxTries + " wrong guesses left.");
    }THANKS

  • Hangman game - logic problem

    Hello, im trying to make it so that when an incorrect letter is chosen (arrayToPass does not contain string) the picture of the hangman is drawn.
    I want count to go up to the number of incorrect attempts so that the appropriate picture is shown - not sure where I would put this though (count).
    Generaly having trouble understanding the logic for this.
    Please give some hints
    Commented out code is various stuff ive tried already and i did not see a forum for logic therefore i think this is right.
         public void actionPerformed(ActionEvent e)
              boolean b = false;
              int count = 0;
              ImageIcon icon = null;
              String s = e.getActionCommand();
              String string = s.toLowerCase();
              b = arrayToPass.indexOf(string) > -1; //Sees if array word has letter in radiobutton in it
              //Split the word into an array
              char[] chr = arrayToPass.toCharArray();
              if(b == true) //If the word holds that letter
                   //String tempString = new Character(chr[1]).toString();
                   //jtp.setText("Correct");
                   for(int k = 0; k < chr.length; k++)
                        String ss = new Character(chr[k]).toString();
                        jl.setText(ss); //Set label to correct letter found
              else
                   count++;
                   if(count == l)
                        icon = new ImageIcon("E:\\HangMan1.jpg");
                        jtp.insertIcon(icon);
                   else if(count == 2)
                        icon = new ImageIcon("E:\\HangMan2.jpg");
                        jtp.insertIcon(icon);
                   else if(count == 3)
                        icon = new ImageIcon("E:\\HangMan3.jpg");
                        jtp.insertIcon(icon);
                   else if(count == 4)
                        icon = new ImageIcon("E:\\HangMan4.jpg");
                        jtp.insertIcon(icon);
                   else if(count == 5)
                        icon = new ImageIcon("E:\\HangMan5.jpg");
                        jtp.insertIcon(icon);
         }

    Although this is still very simple code, it always pays off to bring structure into your code.
    You have a couple of tasks which you have to fulfill here.
    1) Analyze the game situation.
    2) change your game state accordingly.
    3) display your current game state.
    You can handle these three tasks completely seperate. First, you have to check for your words' validity. Depending on this, you have to change your count. Then, you have to repaint.
    So, what you need is at least a game state object. This one must live as long as the game lives, so fields like your "count" are defintely wrong inside the "actionPerformed" method. Don't misuse the Action Command to carry information. Allow access to your game state object, and store the hangman word there.
    Your word validity check is quite complicated. Maybe it would be a good idea to move it into its own method.
    Your painting method will contain more than just changing your hangman pics. For example, you also have to uncover letters that were hidden before, so maybe you should put this into this method, as well.
    This might look like overkill, but seperating helps you to distinguish between good code and wrong code. It also helps you to mentally concentrate on one specific topic, instead of handling everything as one mesh.

  • Can I Use Game Center With Another iPad User?

    Am I able to play a game simultaneously with another iPad user by using game center? For example, can we play a hangman game against each other from different locations if we do it through game center? And if so, how?
    Thank you.

    This is possible, however it is not as easy as that.
    If you want to allow someone to have access to a purchase you have made on your Apple ID, you must log into their device with your Apple ID and download that purchase..You would then simply log back out again.
    Every purchase you make with your Apple ID gives you the licence to store the purchase accross 5 devices.
    On the other persons device, go to Settings > Store > Apple ID > Sign Out.
    Sign into their device the same way, then go into iBooks > Store > Purchased, and download your book.
    Once downloaded, go back into Settings > Store > Apple ID > Sign Out, then sign back in with their Apple ID.

  • Plz help me on the hangman code

    Consider the venerable "hangman" game, in which a player attempts to guess a word one letter at a time. If you are unfamiliar with hangman, simply google it; you'll be playing in no time.
    Consider the following abstract view of hangman. The input is an unknown word and a sequence of character guesses. There is also an implicit parameter, which is the number of incorrect guesses that may be made before losing the game. Even though you wouldn't implement an interactive hangman game this way, let's model this as:
    static public int hangman (String puzzle, String guesses, int limit)
    Requires: puzzle != null, guesses != null, limit >=0
    Effects: returns the number of the guess that solves the
    puzzle within the given limit on incorrect guesses.
    If the puzzle is not solved within the limit, returns -1.
    e.g.
    hangman ("cat", "abct", 1) is 4 (solved)
    hangman ("cat", "abct", 0) is -1 (hit the limit)
    hangman ("cat", "abcd", 5) is -1 (gave up)
    I wrote the following code but it gives me an error of array index out of bounds exception though it compiles correctly. If someone can help me in correcting the code or point out my mistake.
    public class hangman
    public static int hang(String puz,String gue,int lim)
         int i,j,flag=0,ret=0;
         char p[],g[];
         p=puz.toCharArray();
         g=gue.toCharArray();
         one:
              for(i=0;i<g.length;i++)
                   two:
                   for(j=0;j<p.length;j++)
                        if(g==p[j])
                             //take the element off the p array and resize p
                             if(p.length==1)
                             break one;
                             else
                             char b[]=new char[p.length];
                             for(int k=j+1;k<p.length;k++)
                                  p[k-1]=p[k];
                                  b=p;
                                  p=new char[p.length-1];
                             for(int l=0;i<p.length;l++)
                             p[l]=b[l];
                             continue one;
                        else
                        if(j==p.length-1)
                             flag++;
                        else
                        continue two;
              if(flag>lim)
              return -1;
              else
              return 0;
    public static void main(String args[])
    int ret;
    ret=hang("cat","abct",1);
    System.out.println(ret);

    I wrote the following code but it gives me an error
    of array index out of bounds exception though it
    compiles correctly.I just want to point out a fundamental misunderstanding that this statement suggests you have.
    Compiling just converts your source code into equivalent bytecode. The only errors you'll get during compilation are if the syntax is bad (like you forgot a semicolon, misspelled a method name, have an extra closing brace, etc.) or if you're trying to ues a vairialbe that the copmiler can't be sure will have been initialized, etc.
    Compilation does NOT execute your code, and it has no way to determine the logical problem with, for instance, int[] arr = new int[0];
    int x = arr[999]; The fact that x has zero elements and you're trying to access element 999 only comes to light at execution time.
    So "I get an error at runtime even though it compiles fine" is kind of meaningless.
    Note that I'm not trying to pick on you here. I just want to shift your thinking away from this fundamental misconception you seem to have.

  • Problems with a little game...

    I'm trying to write a small game, but I seem to have some problems: forgetting all the unimportant parts, the game consists of a class Hang (it's a Hangman game, but the rulls are different), which is a JFrame, whose only child component is a instance of class Game, which extends JPanel. This class has all the components used in the game's GUI. On one of the components I have to draw, using it's Graphics2D object, so
    for now class Game has a method paintPic(int) as follows:
    public void paintPic(int pic)
         Graphics2D g = (Graphics2D) draw.getGraphics();
         Main.pics[pic].paintIcon(draw,g,0,0);
    }This way class Main (which controls the whole game, has the main(String[]) method and has all methods static) can draw pics on the component (which is draw, an instance of JPanel). The pics are stored in a static ImageIcon[] array belonging to Main. After the Hang object is created and passed a Game object to it (in the constructer) to add it to it's content pane, Main calls the paintPic(int) method to paint a image. The image appears for a moment when the frame is loaded, then it dissappears... I tried using JApplet and Canvas objects instead of JPanel to draw the image on (the draw object), but the result is even worse, since none of these classes extend JComponent to have setPreferredSize(Dimension), so the drawing surface doesn't appear at all... What can I do?? Please help me..

    There are several problems here: I will point them out in the way you should fix them
    #1) It is not recommended to use swing components for games if you are using Graphics. Try doing this instead:
    - change your Hang class to extend Frame instead of JFrame (Frame is the standard for Java Games using Graphics and it is much lighter than JFrame)
    - Go ahead and use Canvas for the the Game class (it is very lightweight) but lose the paintPic method. You should override the paint(Graphics g) method and do all of your painting there. In your case, the reason why the image disappears is because your OS will trigger paint events which clears what you have drawn once.
    #2) The imageIcon array should be replaced by an Image array.
    #3) Use a Thread to call repaint() at regular intervals which will call your paint method. Also, you should override the update(Graphics g) method. Here is the basics you should know:public class Game extends Canvas{
       protected Thread paintTimer;
       protected long
       public int currentImage;
       public void paint(Graphics g){
          Graphics2D g2D = (Graphics2D)g;
          g2D.drawImage(Main.images[currentImage], 0, 0, this);
       public void update(Graphics g){
          repaint();
       public void setCurrentImage(int pic){
          currentImage = pic;
       // This is a technique to synchronize painting over a constant
       // interval of 25 fps. It is standard procedure for the previous
       // generation of Java rendering. Now we use something called
       // active rendering which is more popular.
       public void startPainting(){
          paintTimer = new Thread(
             new Runnable(){
                public void run(){
                   frameStart  = 0;
                   elapsedTime = 0;
                   Thread t = Thread.currentThread();
                   while(t == paintTimer){
                      frameStart = System.currentTimeMillis();
                      repaint();
                      elapsedTime = System.currentTimeMillis() - frameStart;
                      try{
                         if(elapsedTime < frameRate-3)
                            Thread.sleep(frameRate - elapsedTime);
                         else
                            Thread.sleep(3);
                      }catch(InterruptedException e) {break;}
          paintTimer.start();
       public Game(){
          frameRate = 25/1000;    //25 fps
          currentImage = 0;
          paintTimer = null;
    }If you really want to spice up your performance, you should do a few things (not neccesary but recommended, especially if animation is needed).
    #1) Do all your rendering in the Frame and don't use any other components but the Frame. (If you need other components, create your own VirtualComponent class which is Graphics based NOT swing/awt based).
    #2) Look into using double-buffering (offscreen rendering) techniques.
    #3) If you want to use the best of Java rendering capabilities, look into using fullscreen exclusive mode and the BufferStrategy class (advanced).

  • Hangman for Nokia 3650

    Hi all experts,
    I'm wanting to create a simple hangman game for the Nokia 3650 for a Thesis due in September.
    Can you tell me what emulator and/or development kit I need to download from Nokia or Java in order to get started.
    My first task is to write HelloWorld! on a Nokia Emulator for the 3650!!!
    I'm fairly new to Java programming so I want to keep it as simple as possible for now and then hopefully build up to maybe some sounds and a bit of animation.
    I want look into the possibility of using bluetooth for a 2-player game eventually too.
    Any help/advice/warnings/sympathy/luck would be all gratefully received!!
    Much appreciated
    Natalie.

    Grab the J2ME toolkit version 1 from http://java.sun.com/products/j2mewtoolkit/
    Install & Read Docs

  • How do I get... (Hangman question)

    I'm supposed to be writing a non-graphical Hangman game. I was given a precreated superclass (BasicGame) and I'm supposed to write Hangman as a subclass of BasicGame. I am also supposed to have a 250 char (50 words) string class variable that stores 50 possible words at random and I am supposed to use the string.substring (start, end) method and the string.length() method.
    My question is, how do I get the letter inputted by the user to compare to a specific word in the variable list? I.e. if usersLetter is equal to one of the 5 letters from the chosen word, then do whatever.
    Here is the variable "word list":
         private String itsComputersWordList = "firstbibleshoeshoneyearthgloveapplechildshipsboatsaortaacidsallowroadsburntbusesdocksbucksbuddydudesudderembedemberelveseggedentryebonydunesdoweldozeldoorsdiverdisksdirksdinerdualsfrothelbowfryerfrozefrownfretsfumedgullsgulpedhairyhabitlinenlilacmedal";I ask the user for a letter, via this:
    String questionInput = JOptionPane.showInputDialog
                             ("Choose a letter. (Please type in lowercase)");I don't know if I explained this properly, but hopefully you understand. If you don't, please feel free to ask me.
    Edited by: Pluberus on Nov 19, 2008 2:12 PM

    try this
    create a for loop that checks the userLetter against every position in the 5 letter word ie. (something) like this
    checkingWord: is the 5 letter word that the user is trying to guess
    contained: is a boolean that is only true if the userLetter is contained in checkingWord
    there is a really cheap and easy way of searching for a letting in a string that uses something like
    String.contains(UserLetter);, but you have to use the .subString and .length methods so...
    boolean contained = false;
    for(int i = 0; i < checkingWord.length; i++)
          if(userLetter.equalsIgnoreCase(checkingWord.subString(i, i + 1))
                 contained = true;
    return contained;Now you said you had to create a NON graphical hangman game, so it would probably be best to use the scanner class
    the scanner class is a way of inputting (any type of) data, with out the use of a frame / panel / JOptionPane ect..
    lastly
    a very simple way of dividing up the 250 char string would be to use a for loop and the .substring method something like this...
    for(int i = 0; i < 245; i = i + 5)
    checkingWord = string.subString(i, i + 5);

  • Small Basic Hangman

    Hello! I am trying to create a hangman game using Microsoft Small Basic, but I am failing. Can anyone please help me?
    PS I would appreciate sample code :) 

    Hello DandoonZi, 
    Program number:  KLG451
    Here is a sample code (although this code is more complete than most samples). It's a text version of hangman, which is one way to start off this particular program. It's for two players: one player inputs the
    word and the other player tries to guess the word. The major foundations are established so a graphics version is possible. For future reference, it would be helpful to post any code you have done so far on the forum or you could break down your program into
    smaller parts by focusing one part and making it the topic of your post. Like litdiv said, you could focus on how you would approach the game in real life. For instance, hangman consist of these major components: 
    1. One person creates the word to be guessed.
    2. The game begins. Another person evaluates the word by guessing one letter at a time.
    3. An individual's decision has two outcomes: if letter is correct then character is printed as an added clue or if incorrect then penalized by having one less chance to guess. 
    Steps 2-5 are repeated until the player runs out of chances or manage to guess all the characters before running out of chances.
    Now, let's translate the previous steps to a programming perspective:
    1. The word to be guessed is stored into a variable—keyWord—by player 1.
    2. The program then takes keyWord and breaks it down into sub-variables (an array) inside a loop so each letter can be evaluated by the program.
    3. The guess inputted by player 2 will be stored in a variable called input. The variable, input, is then compared to each sub-variables, or also known as indices, inside a loop. If input doesn't match any of the
    indices then player 2 is penalized by subtracting one from the variable, chances, the number of times the player can make a mistake. Otherwise, input is printed (displayed on screen) and the value of numOfCharsLeft, which tracks how many letters are left to
    be guessed, is deducted by one.
    These last two steps are nested inside a large loop (commonly known as the main loop) and constantly repeated until chances is zero, you lose, or numOfCharsLeft is zero, you win. 
    Getting back to the forums. Let's say you are stuck on step 2 of your development process then you can make this the topic of your post and describe the details of your problem. The more specific you are the better
    we can help you. Everyone benefits.
    I recommend keeping these questions in mind while writing any program: Can I write this code better? How well do I know my program? How do I keep the code in my main loop minimal?    
    The program provided is straight forward and worked when I ran it. If something doesn't work right please let me know. 
    Hope this helps. 

  • Problem with String in a Vector

    I'm making a small hangman game. And I got a problem with putting words in a Vector... This is the code... Can someone tell me what I'm doing wrong?
    // First I define it.
    Vector Words;
    //  Then add the words
    Vector Words = new Vector();
    Words.add(new String("HELLO"));
    Words.add(new String("GOOD BYE"));
    // When I try to get a string from the Vector I use this.
    // The program compiles but when I try to run it I get NullPointerExeption here
    W = (String) Words.elementAt(0);

    Not sure since I cant see all of your code but looks like this might be your problem:
    // First I define it.
    Vector Words; //<-- here you define a Vector named Words that is null
    // Then add the words
    Vector Words = new Vector(); //<-- here you define another vector named Words that holds a reference to a new Vector. This is a different reference than the one created above so you should probably remove the "Vector" part from the beginning of this line. Is this a local variable to a method and the one before is a global variable?
    //Here you probably access the locally created Words vector which is initialized
    Words.add(new String("HELLO"));
    // When I try to get a string from the Vector I use this.
    // The program compiles but when I try to run it I get NullPointerExeption here
    W = (String) Words.elementAt(0); //<--and here my guess is that this statement is inside another method than the one with the local Words vector defined. Thus this one accesses the global Words Vector that is never initalized and is Null. And that gives you the NullPointerException.
    So try changing the statement
    Vector Words = new Vector();
    to
    Words = new Vector();
    or just remove it totally and move the Vector creation to the place where you introduce the global variable.
    Of course I might be totally wrong since I cant see all of your code but that is my guess.
    Hope it helps,
    -teka

  • Comparing an Item in a List to...

    Hello. I'm new to these forums, and this is my first post here. I'm working on a hangman game just for fun, and I've run into a snag. When it checks to see if the key pressed is equal to (or the same as) the letter in position x. Every time, even if the letter is in the word, it returns false and does nothing. I hope this is clear. Below is my entire code (just to give you an idea of how this works) of my main class. There is another class that contains methods, but it does not affect this problem.
    Also note that I am fairly new to Java, but have been programming in Python for about half a year now (taking a programming class at my High School). I also so PHP, but even with a good programming background, I still seem to run into snags while programming in Java.
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class Hangman extends JFrame implements ActionListener, KeyListener {
        // Initiate some global variables
        int num_guesses;
        String word;
        String end_round = "yes";
        String[] blanks;
        String[] letters;
        // Get the word list
        String location = "C:/Documents and Settings/AMT/My Documents/My Programs/Java/Hangman/build/classes/hangman_words.txt";
        Vector words = hmFunctions.getWords(location);
        Vector backUpWords = words;
        // Create the main buttons
        JButton hint = new JButton("Hint");
        JButton giveup = new JButton("I Give Up");
        JButton help = new JButton("Help");
        JButton about = new JButton("About");
        JButton quit = new JButton("Quit");
        // Create the main window and add componants
        public Hangman() {
            super("Hangman v1.0");
            setSize(631, 510);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            // Create the main pane
            Container hm_pane = getContentPane();
            hm_pane.setLayout(null);
            hm_pane.setFocusable(true);
            hm_pane.addKeyListener(this);
            // Set the button properties
            hint.setBounds(new Rectangle(2, 444, 100, 30));
            hint.addActionListener(this);
            giveup.setBounds(new Rectangle(130, 444, 100, 30));
            giveup.addActionListener(this);
            help.setBounds(new Rectangle(260, 444, 100, 30));
            help.addActionListener(this);
            about.setBounds(new Rectangle(390, 444, 100, 30));
            about.addActionListener(this);
            quit.setBounds(new Rectangle(520, 444, 100, 30));
            quit.addActionListener(this);
            // Add Componants to interface pane
            hm_pane.add(hint);
            hm_pane.add(giveup);
            hm_pane.add(help);
            hm_pane.add(about);
            hm_pane.add(quit);
            setContentPane(hm_pane);
            setVisible(true);
        // Check to see if they clicked anything
        public void actionPerformed(ActionEvent event) {
            Object source = event.getSource();
            if (source == hint) {
            } else if (source == giveup) {
            } else if (source == help) {
                JOptionPane.showMessageDialog(null, "JHangman v1.0 Help...");
            } else if (source == about) {
                JOptionPane.showMessageDialog(null, "JHangman v1.0\nProgrammed by...");
            } else if (source == quit) {
                System.exit(0);
        // Check if user pressed any keys
        public void keyTyped(KeyEvent key_event) {
            if (end_round == "yes") {
                mainGame("start");        
            } else if (end_round == "no") {
                Character key = key_event.getKeyChar();
                String let = key.toString();
                System.out.println("Letter Pressed: " + let);
                mainGame(let);
        public void keyPressed(KeyEvent key_event) {  
        public void keyReleased(KeyEvent key_event) {
        // The check letter method
        public void mainGame(String funct) {
            if (funct == "start") {
                num_guesses = 0;
                // Check if words empty
                if (words.size() == 0) {
                    words = backUpWords;
                // Get word needed for the game and back up
                word = hmFunctions.getRndWord(words);
                words.remove(word);
                // Create the blanks and letters vector
                letters = new String[word.length()];
                blanks = new String[word.length()];
                // Make the blanks and letters and draw interface
                for (int a = 0; a < word.length(); a++) {
                    blanks[a] = "_";
                    letters[a] = word.substring(a, a + 1);
                System.out.println("Game Started!");
                System.out.println("Blanks and letters added successfuly!");
                end_round = "no";
            // If no other instruction given, then check to see if key pressed is in the word
            } else {
                for (int x = 0; x < word.length(); x++) {
                    if (funct == letters[x]) {
                        blanks[x] = funct;
                    System.out.println(blanks[x] + " ");
                num_guesses += 1;
                if (num_guesses == 8) {
                    end_round = "yes";
        // Main Program
        public static void main(String[] arguments) {
            hmFunctions hm_fct = new hmFunctions();
            // Draw the main interface
            Hangman HM_Window = new Hangman();
    }Any help would be greatly appriciated!

    Of course, looking more closely, you do seem to be assigning the literal reference into the String object reference. In String s = "a string literal";
    if ( s == "a string literal" )
      // process
    } you may actually get into the if block. I would have to test to be sure. However, in general practice, if you want to check to see if two String objects have the same contents, use equals(). If you want to see if two object references point to the same location in memory, use ==. Primitives, of course, are compared with ==.
    Your keyTyped() method checks for two values of end_round. Have you checked for neither the if nor the else conditions being true?
    Do you know if you are getting into your mainGame() method? Try putting a println() in as soon as you enter, so you know you got there and you know the actual parameter value.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Camera On My Blackberry Goes Green When Taking A Picture

    Okay So I try to take a picture on my phone, and you can see fine, the camera works and you see everything through it but when I take a picture it takes a long time to load and then it shows that it took the picture but when it is going to save my screen goes green. 
    Has this happened to anyone? Can someone help me please? 

    I am having the same problem. My camera worked fine since I had it, then suddenly the same green screen every time the picture saves.  I have no memory problems with my phone and have no downloaded any new apps.
    ***Update***
    Don't know if this was the problem or not, but I recently removed some unwanted programs from my phone.  A free hangman game as well as some others (All free games downloaded from the bb app store). They were removed after I found out my phone camera wasn't working for other reasons.  I just checked my camera again to show my wife the prob and now it works!

  • JavaScript -- Forgive me...

    I have the following script running on a JSP page for a hangman game. It works great in IE and Opera, but not Firefox or Netscape:
    <script type="text/javascript" language="JavaScript">
         function submitGuess() {
              var code;
              var evt = window.event;
              var code = (evt.charCode) ? evt.charCode :
                           ((evt.keyCode) ? evt.keyCode :
                          ((evt.which) ? evt.which : 0));
              var character = String.fromCharCode(code);
              document.location = '?guess=' + character;
    </script>
    <body onkeypress="submitGuess();">
    ...Anyone know hwo to write this so it will work in Firefox and/or Netscape?
    Thanks in advance. I'm trying to make many of our text based graphical JSP games more accessible...

    Thank you. I'm now up to:
    <script language="JavaScript">
           function submitGuess(evt) {
              var code;
              if (! evt) {
                   evt = window.event;
              var code = (evt.charCode) ? evt.charCode :
                       ((evt.keyCode) ? evt.keyCode :
                       ((evt.which) ? evt.which : 0));
              var character = String.fromCharCode(code);
              document.location = '?guess=' + character;
    </script>
    <body onkeypress="submitGuess();">
    ...I still don't appear to be getting the events passed in Firefox/Netscape. Is it possible that Firefox/Netscape doesn't assign a keypressed event listener in the body (document) object?

  • Virus........ Bacterial infection ??

    Seems like a virus------ For some time now, sync to itunes on mac from iphone got slower and slower in some hang up with iphoto import.... the functioning of the camera on iphone slowed down and i noticed my iphoto library bizarrely multiplying... when iphoto disappeared from dock and hard drive, the iphone sync used image capture... apple phone support helped me reinstall iphoto and transfer the photos from image capture to iphoto uncovering photos that had been copied over and over.. apple phone support insisted that i was not selecting apply "do not import duplicates".... anyhow, As i went through the 8000 photos in iphoto library to delete out the copies, i began noticing groups of weird symbols, that began displaying as though they were pictures i had taken.. they seemed to be "uncovering" as i deleted out the bulk of the photo copies... some of the pictures where as if i took a close-up photo with my iphone of the "hangman" game on a piece of paper.... groupings of diamonds and weird cartoon characters "uncovered"... my iphone camera roll began displaying "black patches" over or between the photos on the iphone camera roll ....
    the guys at apple phone support were only familiar with the group of diamond/gem type symbols/sections and said that i had imported part of the operating system from ichat into iphoto from the iphone..... as of now, my iphone photo and iphoto are not working properly.... there is some type of corruption and i drug it right onto my new iphone4
    Hopefully i find someone familiar with this issue to remove the corruption so that i can use iphoto and the iphone camera...... Thankyou for your interest

    No such animal in the mac os... windows? Yes.. unless you got Microsoft Security Essentials.. Just because you install windows on your mac doesn't make you immune from viruses.. when you select your windows bootcamp drive, its as if you are using a windows pc - sorta.

  • Illegal start to expression - java applet

    Hi Guys,
    this code is for a hangman game which will be in an applet. When I try putting the buttons in init, I'm getting an "illegal start of expression" for each button. Can someone tell me what I'm doing wrong?
    Cheers,
    * @(#)Hangman.java
    * Sample Applet application
    * @author
    * @version 1.00 06/10/17
    import java.util.Random;
    import java.util.*;
    import java.awt.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.BorderLayout;
    public class Hangman extends JApplet implements ActionListener
         Scanner textfile =new Scanner ("list.txt"); //file with words in
         int count=0;//count number of letters in chosen word
         int lives=6;//lives left
         String [] list= new String [count]; //word chosen stored in array
         boolean [] listDisplay=new boolean [count]; //whether letters in word have been guessed correct
         String guess=null; //guess
         boolean cont=false; //whether game continues or not
         public void read()
              try
                   while (textfile.hasNext()==true)
                        count++;
                   for (int i=0;i<count;i++)
                        String input=null;
                        list=input;
              catch (InputMismatchException e)
              System.out.println ("Mismatch exception:" + e );
         public String selectWord()
              int index=0;
              Random ind=new Random();
              String word=null;
              index=ind.nextInt();
              word=list[index];
              return word;
         public void wrongGuess(int lives)
              switch (lives)
                   case 6:               
                   break;
                   case 5:
                   break;
                   case 4:
                   break;
                   case 3:
                   break;
                   case 2:
                   break;
                   case 1:
                   break;
                   case 0:
                   cont=false;     
         public void game()
              String word=null;
              read();
              word=selectWord();
              while (cont==true)
         public void check(String letter)
              boolean tried=false;
              for (int i=0;i<list.length;i++)
                   if (list[i]==letter)
                        listDisplay[i]=true;
                   else
                        if (tried==false)
                             lives--;
                             tried=true;//guard to stop multiple lives lost by 1 letter
         public void init()
              //setup buttons
              private JButton jbtA=new JButton("A");
              private JButton jbtB=new JButton("B");
              private JButton jbtC=new JButton("C");
              private JButton jbtD=new JButton("D");
              private JButton jbtE=new JButton("E");
              private JButton jbtF=new JButton("F");
              private JButton jbtG=new JButton("G");
              private JButton jbtH=new JButton("H");
              private JButton jbtI=new JButton("I");
              private JButton jbtJ=new JButton("J");
              private JButton jbtK=new JButton("K");
              private JButton jbtL=new JButton("L");
              private JButton jbtM=new JButton("M");
              private JButton jbtN=new JButton("N");
              private JButton jbtO=new JButton("O");
              private JButton jbtP=new JButton("P");
              private JButton jbtQ=new JButton("Q");
              private JButton jbtR=new JButton("R");
              private JButton jbtS=new JButton("S");
              private JButton jbtT=new JButton("T");
              private JButton jbtU=new JButton("U");
              private JButton jbtV=new JButton("V");
              private JButton jbtW=new JButton("W");
              private JButton jbtX=new JButton("X");
              private JButton jbtY=new JButton("Y");
              private JButton jbtZ=new JButton("Z");
              JPanel p1=new JPanel();
              p1.add(jbtA);
              p1.add(jbtB);
              p1.add(jbtC);
              p1.add(jbtD);
              p1.add(jbtE);
              p1.add(jbtF);
              p1.add(jbtG);
              p1.add(jbtH);
              p1.add(jbtI);
              p1.add(jbtJ);
              p1.add(jbtK);
              p1.add(jbtL);
              p1.add(jbtM);
              p1.add(jbtN);
              p1.add(jbtO);
              p1.add(jbtP);
              p1.add(jbtQ);
              p1.add(jbtR);
              p1.add(jbtS);
              p1.add(jbtT);
              p1.add(jbtU);
              p1.add(jbtV);
              p1.add(jbtW);
              p1.add(jbtX);
              p1.add(jbtY);
              p1.add(jbtZ);
              getContentPane().add(p1,BorderLayout.CENTER);
         public void start()
              game();
         public void paint(Graphics g)
              g.drawString("Welcome to Java!!", 50, 60 );
         public void actionPerformed(ActionEvent e)
              if (e.getSource()==jbtA)
                   check("A");
              if (e.getSource()==jbtB)
                   check("B");
              if (e.getSource()==jbtC)
                   check("C");
              if (e.getSource()==jbtD)
                   check("D");
              if (e.getSource()==jbtE)
                   check("E");
              if (e.getSource()==jbtF)
                   check("F");
              if (e.getSource()==jbtF)
                   check("F");
              if (e.getSource()==jbtG)
                   check("G");
              if (e.getSource()==jbtH)
                   check("H");
              if (e.getSource()==jbtI)
                   check("I");
              if (e.getSource()==jbtJ)
                   check("J");
              if (e.getSource()==jbtK)
                   check("K");
              if (e.getSource()==jbtL)
                   check("L");
              if (e.getSource()==jbtM)
                   check("M");
              if (e.getSource()==jbtN)
                   check("N");
              if (e.getSource()==jbtO)
                   check("O");
              if (e.getSource()==jbtP)
                   check("P");
              if (e.getSource()==jbtQ)
                   check("Q");
              if (e.getSource()==jbtR)
                   check("R");
              if (e.getSource()==jbtS)
                   check("S");
              if (e.getSource()==jbtT)
                   check("T");
              if (e.getSource()==jbtU)
                   check("U");
              if (e.getSource()==jbtV)
                   check("V");
              if (e.getSource()==jbtW)
                   check("W");
              if (e.getSource()==jbtX)
                   check("X");
              if (e.getSource()==jbtY)
                   check("Y");
              if (e.getSource()==jbtZ)
                   check("Z");
    /code]

    cheers for the reply :)
    I've managed to compile the file, but nothing is displayed. I'm compiling using JDK 5. Any ideas?
    * @(#)Hangman.java
    * Sample Applet application
    * @author
    * @version 1.00 06/10/17
    import java.util.Random;
    import java.util.*;
    import java.awt.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.BorderLayout;
    public class Hangman extends JApplet implements ActionListener
         Scanner textfile =new Scanner ("list.txt"); //file with words in
         int count=0;//count number of letters in chosen word
         int lives=6;//lives left
         String [] list= new String [count]; //word chosen stored in array
         boolean [] listDisplay=new boolean [count]; //whether letters in word have been guessed correct
         String guess=null; //guess
         boolean cont=false; //whether game continues or not
         JButton jbtA;
         JButton jbtB;
         JButton jbtC;
         JButton jbtD;
         JButton jbtE;
         JButton jbtF;
         JButton jbtG;
         JButton jbtH;
         JButton jbtI;
         JButton jbtJ;
         JButton jbtK;
         JButton jbtL;
         JButton jbtM;
         JButton jbtN;
         JButton jbtO;
         JButton jbtP;
         JButton jbtQ;
         JButton jbtR;
         JButton jbtS;
         JButton jbtT;
         JButton jbtU;
         JButton jbtV;
         JButton jbtW;
         JButton jbtX;
         JButton jbtY;
         JButton jbtZ;
         public void read()
              try
                   while (textfile.hasNext()==true)
                        count++;
                   for (int i=0;i<count;i++)
                        String input=null;
                        list=input;
              catch (InputMismatchException e)
              System.out.println ("Mismatch exception:" + e );
         public String selectWord()
              int index=0;
              Random ind=new Random();
              String word=null;
              index=ind.nextInt();
              word=list[index];
              return word;
         public void wrongGuess(int lives)
              switch (lives)
                   case 6:               
                   break;
                   case 5:
                   break;
                   case 4:
                   break;
                   case 3:
                   break;
                   case 2:
                   break;
                   case 1:
                   break;
                   case 0:
                   cont=false;     
         public void game()
              String word=null;
              read();
              word=selectWord();
              while (cont==true)
         public void check(String letter)
              boolean tried=false;
              for (int i=0;i<list.length;i++)
                   if (list[i]==letter)
                        listDisplay[i]=true;
                   else
                        if (tried==false)
                             lives--;
                             tried=true;//guard to stop multiple lives lost by 1 letter
         public void init()
              //setup buttons
              jbtA=new JButton("A");
              jbtB=new JButton("B");
              jbtC=new JButton("C");
              jbtD=new JButton("D");
              jbtE=new JButton("E");
              jbtF=new JButton("F");
              jbtG=new JButton("G");
              jbtH=new JButton("H");
              jbtI=new JButton("I");
              jbtJ=new JButton("J");
              jbtK=new JButton("K");
              jbtL=new JButton("L");
              jbtM=new JButton("M");
              jbtN=new JButton("N");
              jbtO=new JButton("O");
              jbtP=new JButton("P");
              jbtQ=new JButton("Q");
              jbtR=new JButton("R");
              jbtS=new JButton("S");
              jbtT=new JButton("T");
              jbtU=new JButton("U");
              jbtV=new JButton("V");
              jbtW=new JButton("W");
              jbtX=new JButton("X");
              jbtY=new JButton("Y");
              jbtZ=new JButton("Z");
              JPanel p1=new JPanel();
              p1.add(jbtA);
              p1.add(jbtB);
              p1.add(jbtC);
              p1.add(jbtD);
              p1.add(jbtE);
              p1.add(jbtF);
              p1.add(jbtG);
              p1.add(jbtH);
              p1.add(jbtI);
              p1.add(jbtJ);
              p1.add(jbtK);
              p1.add(jbtL);
              p1.add(jbtM);
              p1.add(jbtN);
              p1.add(jbtO);
              p1.add(jbtP);
              p1.add(jbtQ);
              p1.add(jbtR);
              p1.add(jbtS);
              p1.add(jbtT);
              p1.add(jbtU);
              p1.add(jbtV);
              p1.add(jbtW);
              p1.add(jbtX);
              p1.add(jbtY);
              p1.add(jbtZ);
              getContentPane().add(p1,BorderLayout.CENTER);
         public void start()
              game();
         public void paint(Graphics g)
              g.drawString("Welcome to Java!!", 50, 60 );
         public void actionPerformed(ActionEvent e)
              if (e.getSource()==jbtA)
                   check("A");
              if (e.getSource()==jbtB)
                   check("B");
              if (e.getSource()==jbtC)
                   check("C");
              if (e.getSource()==jbtD)
                   check("D");
              if (e.getSource()==jbtE)
                   check("E");
              if (e.getSource()==jbtF)
                   check("F");
              if (e.getSource()==jbtF)
                   check("F");
              if (e.getSource()==jbtG)
                   check("G");
              if (e.getSource()==jbtH)
                   check("H");
              if (e.getSource()==jbtI)
                   check("I");
              if (e.getSource()==jbtJ)
                   check("J");
              if (e.getSource()==jbtK)
                   check("K");
              if (e.getSource()==jbtL)
                   check("L");
              if (e.getSource()==jbtM)
                   check("M");
              if (e.getSource()==jbtN)
                   check("N");
              if (e.getSource()==jbtO)
                   check("O");
              if (e.getSource()==jbtP)
                   check("P");
              if (e.getSource()==jbtQ)
                   check("Q");
              if (e.getSource()==jbtR)
                   check("R");
              if (e.getSource()==jbtS)
                   check("S");
              if (e.getSource()==jbtT)
                   check("T");
              if (e.getSource()==jbtU)
                   check("U");
              if (e.getSource()==jbtV)
                   check("V");
              if (e.getSource()==jbtW)
                   check("W");
              if (e.getSource()==jbtX)
                   check("X");
              if (e.getSource()==jbtY)
                   check("Y");
              if (e.getSource()==jbtZ)
                   check("Z");

Maybe you are looking for

  • How do I save a Spreadsheet generated by Reportserver as xls file

    Hi to all, I have to implement a form that is able to generate 3 or 4 or even more Excel files (depends which one the user has chosen)and I have some Problems, so I hope any one can help me here. 1. I want to start the reports sequential. I tried lik

  • My X2-01 IS IN TROUBLE...PLS HELP!!!!!!!!!!!!

    I was browsing in google one day then suddenly my phone light dimmed then i trying pressing the red decline button but nothing happened, then i kept pressing it continuosly and my phone switched off. After that I turned it back on and found everythin

  • Combobox Items vanishing?

    I have a problem with ComboBox selection. Items above the last selected seem to be vanishing from the list. I'll show my xaml and then explain: <ComboBox x:Name="cmbFirmness" HorizontalAlignment="Left" Margin="86,106,0,0" VerticalAlignment="Top" Widt

  • Help! Authorization question

    OK, this might be a silly question, but I thought I'd give it a shot. I have iTunes installed on two computers. One doesn't have the internet hooked up and to listen to certain songs, it says I need to authorize them. So is there any way I can author

  • Why start iCloud drive when Yosemite is not ready? Once accidental start iCloud drive, no downgrade option?

    When IOS8 is release there is a simple switch to start iCloud Drive.  It is a nightmare.  My iWork field can no longer be sync with my Mac and Mac Air. There is no downgrade method to resume the usual iCloud support.  Yosemite is not ready now. There