I'm supposed to make a basic memory game. Buttons will appear on a grid layout in variations of 2x2, 4x4 and 6x6. How do I know which button was pressed?
Those are the buttons. I was planning on comparing the strings sent by the buttons pressed to see if they were similar or not, and work from there. But how do I even know which button was clicked... Any help would be greatly appreciated. Thanks.
you can use e.getActionCommang() to get the text of the button in case you have some text in them.
posted 11 years ago
This is how my actionperformed looks like right now.
My problem is, how to access the button that was clicked. Like, when the button is clicked, I'd want to change the foreground color to white, wait for the second button to be clicked, compare the values and work from there... I can't find any way to find out or manipulate whichever button was clicked...
Register an individual listener per button that simply knows which button it belongs to!
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus