Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 27 of 27

Thread: Memory Card Game JButtons Array

  1. #26
    Junior Member
    Join Date
    Feb 2012
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Memory Card Game JButtons Array

    Step 2, button shows an image. I changed my code around to save the images differently, but now I'm not sure what would go in the mouseClick event to show one image once that button is clicked. Here's what I have.

    public class Layout extends JButton implements MouseListener{
     
    	JButton[][] button = new JButton[6][5];
    	String[] imageNames = {"blanton.jpg", "brown.jpg", "halladay.jpg", "hamels.jpg", "howard.jpg", "lee.jpg", "mayberry.jpg", "papelbon.jpg", "pence.jpg",
    			"polanco.jpg", "rollins.jpg", "ruiz.jpg", "utley.jpg", "victorino.jpg", "worley.jpg"};
    	ArrayList<ImageIcon> images = new ArrayList<ImageIcon>();
     
    public void jpanel(){
    for(int i=0; i<imageNames.length; i++){
    			images.add(new ImageIcon(imageNames[i]));
    		}
    		Collections.shuffle(images);
     
    		int count = 0;
    		for(int i=0; i<button.length; i++){
    			for(int j=0; j<button[i].length; j++){
    				button[i][j] = new JButton();
    				button[i][j].setIcon(images.get(count%images.size()));
    				count++;
    			}
    		}
    	public void mouseClicked(MouseEvent event){
    		//show image on the button that was pressed
    	}

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Memory Card Game JButtons Array

    Make a list of the steps for Step 2 - "button shows image" before writing the code.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Problem with Memory Card Game
    By rlo10 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 18th, 2012, 09:09 PM
  2. A Card Game
    By Paytheprice in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 25th, 2012, 06:30 AM
  3. Card Game Problem.
    By d'fitz in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 5th, 2011, 07:30 AM
  4. Card Game help....
    By macFs89H in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 2nd, 2011, 07:55 AM
  5. Card Game Problem....Need Help
    By macFs89H in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2011, 07:30 AM