Results 1 to 5 of 5
Thread: Guessing Game
- 10-27-2010, 01:47 PM #1
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
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 classLast edited by rose; 10-27-2010 at 04:01 PM.
- 10-27-2010, 02:46 PM #2
Seriously?
The responses you received in your other post haven't changed.
Need help in Guessing Game
- 10-27-2010, 02:59 PM #3
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
Can you please tell me how to delete any of the thread?
- 10-27-2010, 03:01 PM #4
- 10-27-2010, 08:00 PM #5
Similar Threads
-
Need help in Guessing Game
By rose in forum Java GamingReplies: 4Last Post: 10-27-2010, 10:43 PM -
Help with a word guessing game.
By The_Round_One in forum New To JavaReplies: 6Last Post: 05-19-2010, 04:22 AM -
guessing game help
By yasmin k in forum AWT / SwingReplies: 4Last Post: 10-31-2009, 05:37 PM -
guessing game using GUI
By yasmin k in forum New To JavaReplies: 1Last Post: 10-26-2009, 12:13 PM


LinkBack URL
About LinkBacks


Bookmarks