Results 1 to 10 of 10
  1. #1
    Franneldort is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default Problem with making/sorting a deck of cards

    Thanks for looking at this post!

    I am working on making an applet that displays a deck of cards. The program has three buttons: a show/hide toggleButton, a sort button, and a shuffle button. I've got the three buttons working correctly but I can't get the GUI to display the ranks of the cards. (E.g. as 2d...ace of spades, two of diamonds, etc.) The method that we were assigned to "draw" the cards in is the paint(). The pseudocode for how to get the images in the GUI is there but I have no idea what the syntax is going to be. My problem is, how do I get the GUI to display the ranks of the cards? Thanks for any help. :)
    Attached is my current program. The paint() is in the CardApplet class.
    Attached Files Attached Files

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    how do I get the GUI to display the ranks of the cards
    Not sure of your terms. Is Ace a rank?

    You need a lot more description of the problem.
    How are you going to display the cards? One at a time or a full hand of cards? Do you have images for all the different cards or are you going to use text?

    You should only use the paint() method to do the drawing of images or text, do the computations outside of paint and call repaint when you want to show something.

  3. #3
    Franneldort is offline Member
    Join Date
    Oct 2008
    Posts
    19
    Rep Power
    0

    Default

    Yes I do plan on making the computations outside of the paint method and then calling it. As for the ranks, the first character will be the rank of the card such as, " 2, 5, ace, king" and the second character in the rank is the suit. "d for diamond, s spades, c clubs, h hearts." I have images for all of the cards I am going to use. They will be displayed in four rows, one row for each suit. The ranks will be displayed separately. These will just be two characters in the same four rows as the actual images.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    Look at the Graphics drawImage and the drawString methods.
    Get the size of all the images and layout on a piece of paper how you want to display to look. Using the size of the images, you can assign positions to where to draw the images. Then figure out where to put the text relative to the images. You will need x,y positions for the location of each image and string to use the draw methods. drawImage has many overloads. If you do a search on the forum you'll find some code examples.

  5. #5
    jtg2507 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    I have to do the same problem, but I cant use the drawImage and drawString methods.

  6. #6
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    would a LabelProvider work for this? I know I can store images in a folder in my project and the LabelProvider can attach them to menus, buttons, view tabs, etc.

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    I cant use the drawImage and drawString methods
    What does that mean? The assignment says that you can't use those methods
    Or you don't know how to use them. There are many sample codes on this forum. Use search to find them.

  8. #8
    jtg2507 is offline Member
    Join Date
    Nov 2008
    Posts
    2
    Rep Power
    0

    Default

    Here is what I have so far:
    I do not know where to go next
    Attached Files Attached Files

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    You need to descibe what it is that you want the program to do.
    Then show what you've tried to do to make the program do it and ask questions about the problems you are having.
    Your code has no comments describing what it is supposed to do. How can anyone make recommendations if there are no specifications on what the code is to do?

    It would be easier for people to look at your code if all of it was in a single file, vs 3.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I do not know where to go next
    Overly general and vague questions of this form are very hard if not impossible to answer and ask too much from the volunteers here. To fix this you need to make some decisions and do some work.
    1) Do you have problems with your code? if so work on them one at a time and then come back with specific questions and your code.
    2) Do you want to extend your currently functioning code? Again if so, try to do this first yourself, then if you run into stumbling blocks come back with code posted in the forum and a specific question.

    two resources that may help you help us so that we can better help you include the following:

    How to ask Smart Questions
    How to create an SSCCE

    Much luck!

Similar Threads

  1. Sorting JTable (Vectors) Problem
    By ramapple in forum AWT / Swing
    Replies: 6
    Last Post: 07-06-2009, 11:15 PM
  2. creating a deck of cards using a linked list
    By boomba88 in forum New To Java
    Replies: 2
    Last Post: 09-11-2008, 03:34 PM
  3. sorting problem...
    By mark-mlt in forum New To Java
    Replies: 4
    Last Post: 04-17-2008, 02:15 PM
  4. sorting problem
    By mcal in forum New To Java
    Replies: 1
    Last Post: 02-14-2008, 08:13 AM
  5. Problem with sorting Table
    By sireesha264 in forum Advanced Java
    Replies: 0
    Last Post: 02-08-2008, 02:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •