Results 1 to 5 of 5

Thread: Guessing Game

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

    Post 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


    Like mentioned above, we are asked to create buttons with images attached to each button.
    I need some help with images i.e how to attach images to the buttons so it should display when the user clicks the button.
    And also where should I place the code for images?



    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
    Last edited by rose; 10-27-2010 at 05:01 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Seriously?

    The responses you received in your other post haven't changed.

    Need help in Guessing Game

  3. #3
    rose is offline Member
    Join Date
    May 2008
    Posts
    6
    Rep Power
    0

    Default

    Can you please tell me how to delete any of the thread?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default

    Quote Originally Posted by rose View Post
    Can you please tell me how to delete any of the thread?
    Why don't you just edit one so it includes an actual question like you were asked?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    These guys who dump their homework on forums under feminine nics (had quite a spate of them lately) should realize that true geeks and nerds aren't impressed by cyber eyelash-fluttering.

    db
    Last edited by DarrylBurke; 10-27-2010 at 09:02 PM.

Similar Threads

  1. Need help in Guessing Game
    By rose in forum Java Gaming
    Replies: 4
    Last Post: 10-27-2010, 11:43 PM
  2. Help with a word guessing game.
    By The_Round_One in forum New To Java
    Replies: 6
    Last Post: 05-19-2010, 05:22 AM
  3. guessing game help
    By yasmin k in forum AWT / Swing
    Replies: 4
    Last Post: 10-31-2009, 06:37 PM
  4. guessing game using GUI
    By yasmin k in forum New To Java
    Replies: 1
    Last Post: 10-26-2009, 01: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
  •