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.

Results 1 to 2 of 2

Thread: matching game random number problem

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default matching game random number problem

    I am trying to make a matching game where the user selects two images and the program has to check if the images match. I am trying to put random images in buttons and I am getting this error:

    M:\School\ICS4U1\Projects\Matching\MatchingGame.ja va:134: cannot find symbol
    symbol : method generateNewRandom()
    location: class MatchingGame
    gameButton[i].setIcon(images[generateNewRandom()]);
    ^
    M:\School\ICS4U1\Projects\Matching\MatchingGame.ja va:160: incompatible types
    found : java.lang.Object
    required: int
    return numbersList.get(n);

    This is my code:
    /**
     *Matching Game
     *
     *
     * 
     * 2013/2/25
     */
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.*;
    import javax.swing.*;
    import static java.util.Collections.*;
    import javax.swing.ImageIcon.*;
     
    public class MatchingGame extends JFrame implements ActionListener {
    	private JButton exitButton, replayButton;
        private JButton[] gameButton = new JButton[36];
        private ImageIcon[] ImageArray;
     
        public MatchingGame() {
        	setLayout(new BorderLayout());
        	init();
            panel();
            setImages();
            setTitle("MathingGame");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(900, 900);
            setVisible(true);
        }
     
        public void init() {
            for (int i = 0; i < gameButton.length; i++) {
                gameButton[i] = new JButton();
                gameButton[i].addActionListener(this);
            }
            exitButton = new JButton("Exit");
            exitButton.addActionListener(this);
            replayButton = new JButton("Replay");
            replayButton.addActionListener(this);
        }
     
        public void panel() {
     
        	Panel gamePanel = new Panel();
        	gamePanel.setLayout(new GridLayout(6, 6));
     
        	for (int i = 0; i < gameButton.length; i++) {
            	gamePanel.add(gameButton[i]);
        	}
     
        	Panel buttonPanel = new Panel();
        	buttonPanel.add(replayButton);
        	buttonPanel.add(exitButton);
        	buttonPanel.setLayout(new GridLayout(1, 0));
     
        	add(gamePanel, BorderLayout.CENTER);
        	add(buttonPanel, BorderLayout.SOUTH);
     
        }
     
        public void setImages(){
     
        ImageIcon Aquaman = new ImageIcon ("Aquaman.jpg");
        ImageIcon Batman = new ImageIcon ("Batman.jpg");
        ImageIcon CaptainAmerica = new ImageIcon ("CaptainAmerica.jpg");
        ImageIcon Deadpool = new ImageIcon ("Deadpool.jpg");
        ImageIcon FantasticFour = new ImageIcon ("FantasticFour.jpg");
        ImageIcon Flash = new ImageIcon ("Flash.jpg");
        ImageIcon GreenArrow = new ImageIcon ("GreenArrow.jpg");
        ImageIcon GreenLantern = new ImageIcon ("GreenLantern.jpg");
        ImageIcon Hawkeye = new ImageIcon ("Hawkeye.jpg");
        ImageIcon Ironman = new ImageIcon ("Ironman.jpg");
        ImageIcon Punisher = new ImageIcon ("Punisher.jpg");
        ImageIcon RedTornado = new ImageIcon ("RedTornado.jpg");
        ImageIcon Robin = new ImageIcon ("Robin.jpg");
        ImageIcon Spiderman = new ImageIcon ("Spiderman.jpg");
        ImageIcon Superman = new ImageIcon ("Superman.jpg");
        ImageIcon TheAvengers = new ImageIcon ("TheAvengers.jpg");
        ImageIcon Thor = new ImageIcon ("Thor.jpg");
        ImageIcon Wonderwoman = new ImageIcon ("Wonderwoman.jpg");
     
        ImageIcon[] images = new ImageIcon[36];
     
        images[0] = Aquaman;
        images[1] = Batman;
        images[2] = CaptainAmerica;
        images[3] = Deadpool;
        images[4] = FantasticFour;
        images[5] = Flash;
        images[6] = GreenArrow;
        images[7] = GreenLantern;
        images[8] = Hawkeye;
        images[9] = Ironman;
        images[10] = Punisher;
        images[11] = RedTornado;
        images[12] = Robin;
        images[13] = Spiderman;
        images[14] = Superman;
        images[15] = TheAvengers;
        images[16] = Thor;
        images[17] = Wonderwoman;
        images[18] = Aquaman;
        images[19] = Batman;
        images[20] = CaptainAmerica;
        images[21] = Deadpool;
        images[22] = FantasticFour;
        images[23] = Flash;
        images[24] = GreenArrow;
        images[25] = GreenLantern;
        images[26] = Hawkeye;
        images[27] = Ironman;
        images[28] = Punisher;
        images[29] = RedTornado;
        images[30] = Robin;
        images[31] = Spiderman;
        images[32] = Superman;
        images[33] = TheAvengers;
        images[34] = Thor;
        images[35] = Wonderwoman;
     
        for(int i=0; i<36;i++){
        	gameButton[i].setIcon(images[generateNewRandom()]);
     
        }
    	}
     
        public class RandomNumberGenerator {
        ArrayList numbersList = new ArrayList ();
        public RandomNumberGenerator(int length) {
            for(int i=0;i<=36;i++)
                numbersList.add(i);
            Collections.shuffle(numbersList);
        }
        public int generateNewRandom(int n) {
            return numbersList.get(n);
        }
    	}
     
        public void actionPerformed(ActionEvent e) {
    		if (exitButton == e.getSource()) {
    		    System.exit(0);
    		}
    		if (replayButton == e.getSource()) {
     
    		}
        }
     
        public static void main (String[] args){
        	new MatchingGame();
        }
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: matching game random number problem

    cannot find symbol
    symbol : method generateNewRandom()
    Where is that method that takes no args defined? There is a method with the same name that takes an int as arg.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Matching Game Help
    By nubshat in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 2nd, 2013, 03:15 PM
  2. Random Number problem
    By Optimizer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 26th, 2012, 02:23 PM
  3. Matching Pairs game - something's not right?
    By sambar89 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 9th, 2011, 02:54 PM
  4. Reverse Random Number Game
    By koryvandell in forum Java Theory & Questions
    Replies: 2
    Last Post: April 4th, 2011, 01:11 AM