Results 1 to 5 of 5
  1. #1
    rose is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Smile Need help in Guessing Game

    Create a Java JFrame Guessing Game GUI. The GUI should supply a number of button (minimum twelve) with images attached to each button. When the GUI starts the buttons will display a question mark character (“?”; in a nice big format), when the user clicks on one of the buttons an image will be revealed to the user, e.g. it could be an image of an animal. There must be two of each image hidden behind the buttons on the screen, i.e., there are matching pairs to reveal. The user will continue to reveal each of the buttons’ contents until all matching images have been revealed. The score (number of matches) must be displayed on the GUI somewhere, and the user must be informed that they have won the game. A button should also be supplied to reset the game

    Here is my code:


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    public class Guessing extends JFrame implements ActionListener{
    public Guessing() {

    super("Guessing Game");
    Container contentPane = getContentPane();
    JPanel panel = new JPanel();


    JButton myButton1 = new JButton("?");
    myButton1.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton2 = new JButton("?");
    myButton2.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton3 = new JButton("?");
    myButton3.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton4 = new JButton("?");
    myButton4.setFont(new Font("Serif", Font.BOLD,20))

    JButton myButton5 = new JButton("?");
    myButton5.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton6 = new JButton("?");
    myButton6.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton7 = new JButton("?");
    myButton7.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton8 = new JButton("?");
    myButton8.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton9 = new JButton("?");
    myButton9.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton10 = new JButton("?");
    myButton10.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton11 = new JButton("?");
    myButton11.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton12 = new JButton("?");
    myButton12.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton13 = new JButton("?");
    myButton13.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton14= new JButton("? ");
    myButton14.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton15 = new JButton("?");
    myButton15.setFont(new Font("Serif", Font.BOLD,20));

    JButton myButton16 = new JButton("?");
    myButton16.setFont(new Font("Serif", Font.BOLD,20));


    // ADD THE ACTIONLISTENER
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);
    button5.addActionListener(this);
    button6.addActionListener(this);
    button7.addActionListener(this);
    button8.addActionListener(this);
    button9.addActionListener(this);
    button10.addActionListener(this);
    button11.addActionListener(this);
    button12.addActionListener(this);
    button13.addActionListener(this);
    button14.addActionListener(this);
    button15.addActionListener(this);
    button16.addActionListener(this);

    //ADD THE BUTTONS TO THE TABLE
    panel.add(button1);
    panel.add(button2);
    panel.add(button3);
    panel.add(button4);
    panel.add(button5);
    panel.add(button6);
    panel.add(button7);
    panel.add(button8);
    panel.add(button9);
    panel.add(button10);
    panel.add(button11);
    panel.add(button12);
    panel.add(button13);
    panel.add(button14);
    panel.add(button15);
    panel.add(button26);


    //ADD THE PANEL TO THE FRAME ANDDISPLA
    c.add(panel);
    setSize(400,300);
    show();
    }// END CONSTRUCTOR

    public static void main(String args [])
    {
    Guessing myFrame = new Guessing();
    myFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    }


    }//end of class

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default

    Okay, and what's your question? Make sure you use the code tags when posting code.

    Read this: How To Ask Questions The Smart Way

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

    Default

    This is a code dump type question where you have posted the assignment, then the code without asking any questions other than the implied question, "here's my code, fix it for me". You may want to fix this post, since these type of questions generally don't get answered. I suggest you start by asking as specific a question as possible.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default

    Double posted 13 minutes after Fubarable's response here.
    Guessing Game

    db

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

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Double posted 13 minutes after Fubarable's response here.
    Guessing Game

    db
    And it is still nothing more than a code-dump. Posts locked, user banned 1 week.
    Last edited by Fubarable; 10-27-2010 at 10:57 PM.

Similar Threads

  1. Java - number guessing game
    By kev670 in forum Java Applets
    Replies: 3
    Last Post: 10-22-2010, 12:55 AM
  2. Help with a word guessing game.
    By The_Round_One in forum New To Java
    Replies: 6
    Last Post: 05-19-2010, 04:22 AM
  3. guessing game help
    By yasmin k in forum AWT / Swing
    Replies: 4
    Last Post: 10-31-2009, 05:37 PM
  4. guessing game using GUI
    By yasmin k in forum New To Java
    Replies: 1
    Last Post: 10-26-2009, 12:13 PM

Posting Permissions

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