Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Basic Java Class Help

    Java hangman GuessPrase HELP!?
    Create a GuessPhrasePanel class and implement the following (NOTE: Make sure your methods work the same for upper and lower case letters):

    a. Has a constructor taking a String guess phrase

    b. Shows all the letters in the phrase, initially just showing the underline for all alphabet letters (not the letter as it needs to be guessed). Spaces and other punctuation should be shown with no underline.

    c. setPhrase – sets a new phrase to this GuessPhrase object, gets rid of old phrase parts and creates new ones

    d. hasLetter – a method that returns whether or not a specified letter is in the phrase

    e. revealLetter – a method that reveals or shows a specified letter (if there are more than one of that letter, all should be revealed)

    f. isFullPhraseRevealed – returns whether or not the full phrase has been revealed

    g. revealFullPhrase – reveals the full phrase

    PLEASE HELP IM SO LOST I HAVE NO IDEA WHAT TO PUT IN THE METHOD BODIES AND IN MAIN. im just a beginner and my teacher refuses to offer help.
    I was given these instructions and i need to write my own code. this is what i was able to come up with.
    i got like 30-40% i think. but i dont know how to finish.

    if you can tell me how. to do these parts. what they are supposed to look like. if it needs an if statement or not or something like that. just some guidance im soo lost. please if you can suggest anything at all!

    if possible if you can write up the code id really appreciate it, im going to fail the class if i cant get this perfect. IM BEGGING YOU

    my code
    ------------------------------
    Code:
    import java.io.IOException;
    
    import javax.swing.JPanel;
    
    
    public class GuessPhrasePanel extends JPanel {
    
    String phrase;
    
    public GuessPhrasePanel (String phrase){
    
    
    }
    
    public void setPhrase(String p) {
    phrase = p;	
    
    
    }
    
    public boolean hasLetter(char c){
    return hasLetter(c);
    
    }
    public boolean isFullPhraseRevealed(){
    return isFullPhraseRevealed();
    }
    
    public void revealLetter(char c){
    
    }
    
    public void revealFullPhrase(){
    
    }
    public static void main(String[] args) {
    
    GuessPhrasePanel myGuessPhrasePanel = new GuessPhrasePanel;
    
    //(supposed to initialize letters here)
    }
    
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by bballrmx View Post
    PLEASE HELP IM SO LOST I HAVE NO IDEA WHAT TO PUT IN THE METHOD BODIES AND IN MAIN. im just a beginner and my teacher refuses to offer help.
    I was given these instructions and i need to write my own code. this is what i was able to come up with.
    In which case its likely time to contact a department head or dean. Instructors are paid to assist you in the learning process. If you are a beginner, you shouldn't be using GUI's in the first place.

    Since you are using a gui though, the answer is simple: you don't put that in your main methods at all. You attach the event handlers for the keydowns or add a submit button and a ActionListener and chain the events to the method provided by the GuessPhrasePanel. So the main (which I wouldn't put in a panel class) is responsible for instantiating the frame, adding this panel, and attaching the listeners it requires.


  •  

    Tags for this Thread

    Posting Permissions

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