user4775931
user4775931

Reputation:

card dealer java gui

I have to create a GUI application that randomly selects a card from the deck and displays it each time the user clicks on it. After a card is selected it is removed from the deck and can no longer be used. A message should be displayed when there are no more cards left in the deck. I am completely lost and any help would be appreciated.

I forgot to mention that I have pictures to go with each of the cards as well. How would I associate the ID of the card with the picture?

Upvotes: 0

Views: 310

Answers (2)

Josh
Josh

Reputation: 113

You shouldn't expect anyone to do your homework for you but there are at least a couple of things here you could look up to get you started.

I'm also a beginner programmer starting out in Java and my first project involved cards and random card drawing. I stored the deck of cards in a two dimensional array and picked them out randomly by generating two random numbers with Math.Random, one for the suit and one for the card in that suit.

I'm sure there are much, MUCH better ways of solving this but this was the easiest way for me at the time and seemed to do the job.

Upvotes: 1

pasghetti
pasghetti

Reputation: 57

One way this could be done is to make a list of IDs of cards. For example, you could put the 1 of hearts as ID 0, put 1 of aces as ID 1, and so on. Then, you could use the Math.Random class to chose one ID out of the list of IDs whenever the button is clicked, and display the card. Once the card is displayed, remove the ID from the deck so it will not be chosen again.

Upvotes: 0

Related Questions