Results 1 to 6 of 6
  1. #1
    vouslavous is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

    Default more help with my applet

    this is for hangman

    why doesnt this add wrong letters to wrong letter field eventhough it should?
    i attached a pic of the GUI

    Java Code:
    private void guessButtonActionPerformed(java.awt.event.ActionEvent evt) {                                            
    guess = letterEnter.getText();
    boolean letterCorrect = false;
    if (guess.length()>1) //checks to see if the guess is only 1 char long
    {
    letterEnter.setText("");
    }
    else
    {
    for (int i = 0; i<=correctWord.length()-1; i++)  // compares guessletter with every letter in correct word
    {
        String tester = correctWord.substring(i,i+1);
        //System.out.println(guess+"hi");
        if (guess.equals(tester))
        {
            letterCorrect = true;
            correctSpot1.setText(guess);
            break;
        }
        else 
    if (letterCorrect = false)
    {
            System.out.println("aa");
     wrongLetterField.setText(wrongLetterField.getText()+letterEnter.getText());
    }
    }
    }
        }                                           
    
        private void setCorrectWordActionPerformed(java.awt.event.ActionEvent evt) {                                               
    correctWord = wordEnter.getText();
    }

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    Don't know if it will fix the problem your seeing, but you have an error in the following:
    Java Code:
    if (letterCorrect [B][COLOR="Red"]=[/COLOR][/B] false)
    You're doing an assignment... not a comparation. It should be as follows:
    Java Code:
    if (letterCorrect [B][COLOR="Blue"]==[/COLOR][/B] false)
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Or better yet,
    Java Code:
    if (!letterCorrect)

  4. #4
    rexicon is offline Member
    Join Date
    Apr 2009
    Posts
    10
    Rep Power
    0

    Default

    Thats very nice

  5. #5
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    so solved?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  6. #6
    vouslavous is offline Member
    Join Date
    Apr 2009
    Posts
    11
    Rep Power
    0

Similar Threads

  1. 3D Applet
    By DzzD in forum Java Applets
    Replies: 1
    Last Post: 03-30-2009, 11:20 PM
  2. Calling another applet on click of button in one applet
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 1
    Last Post: 02-19-2009, 12:54 PM
  3. Need with an applet
    By maggie_2 in forum Java Applets
    Replies: 6
    Last Post: 09-21-2008, 08:07 PM
  4. Applet
    By kapoorje in forum Java Applets
    Replies: 0
    Last Post: 07-24-2007, 04:06 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •