File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes GUI Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "GUI Question" Watch "GUI Question" New topic

GUI Question

Mark Henderson

Joined: Mar 05, 2010
Posts: 1
I am trying to make a memory card game but im not sure how to get started with the GUI part. I have made the frame and the content pane etc and have a working menubar but as to how I would display 40 cards im not sure. I was thinking of using a grid layout but how would I display the images the correct size and what would happen when the image is actually clicked?? Any help would be greatly appreciated.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
in a simple memory card game, say 16 'cards', it could go something like this

JPanel set as GridLayout(4,4), also setting the gaps
8 images
Image array [16], the images are duplicated
Image array shuffled
16 JButtons (array) added to the JPanel

when program runs, 16 blank buttons appear
click a button and you set the button's icon to the corresponding image array index
repeat for a second button, which triggers a timer to check if the images are the same
if not, set both button's icons to null

should be enough to get you going

Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10826

Welcome to the Ranch.

We have a forum dedicated to UI where UI related questions should be asked. I will move this thread over there for you.
In the meanwhile please do check out

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link:
subject: GUI Question
It's not a secret anymore!