Images in Card Game

Hi there,
I have been programming a variation of a Poker game in Java and have finished most of it in command-line. I need to port it over into a JApplet now and am having a few problems with the images.
As the layout is similar to Hearts, I wanted to use a JFrame, with JPanels for containing each part of the screen. I wanted to have a set of cards overlapping for the N, E, and W panels, but I cannot seem to get the images to show properly... I just get a grey box...
Can someone help and give me some advice on how to do the layout and use the paint facility?

Hi there,
I have been programming a variation of a Poker game in Java and have finished most of it in command-line. I need to port it over into a JApplet now and am having a few problems with the images.
As the layout is similar to Hearts, I wanted to use a JFrame, with JPanels for containing each part of the screen. I wanted to have a set of cards overlapping for the N, E, and W panels, but I cannot seem to get the images to show properly... I just get a grey box...
Can someone help and give me some advice on how to do the layout and use the paint facility?

Similar Messages

  • Need some OO design pointers for a Java card game I wrote for uni

    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
         private int value;                    //variable for the value of the card
         private int suit;                         //variable for the suit of the card
         private ImageIcon frontOfCard;     //Displays the image of the front of the cards
         private ImageIcon backOfCard;          //displays the image of the back of the cards
         public Card (int Value, int Suit, ImageIcon front, ImageIcon back)
              value = Value;               
              suit = Suit;               
              frontOfCard = front;     
              backOfCard = back;
              setIcon(backOfCard);     //To make it non-visible when dealt
         }As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    Card class
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instance
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.
    AI Class extends Player Class
    GUI Class
    Deck Class <-- contains 52 cards
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    Any help on this would be greatly appreciated!
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.

    Faz_86 wrote:
    Hi,
    I hope a few of you Java sifus can help me understand I dilemma I keep finding myself in.
    I created a card game for a university assignment which works great but its not very OO at the moment.
    I only have 3 classes; a Card class, a Deck class and a Game class which contains all my GUI, AI, Game Controller, Player and Hand code.
    The assignment is over but I feel like enhancing the game, adding animation, multiplayer, several AI agents etc.
    Admirable, and the best way to learn, doing something that interests you.
    The first thing I have attempted is animation and I've hit a brick wall. I am trying to create animation for my card game whereby I have an animation showing the cards being shuffled and then an animation which shows the cards being dealt to the players. The game then commences. The cards on the GUI then need to be clickable (MouseListeners?) to play the game. If you're running Windows 7, load up 'Hearts' and you'll know what I'm trying to achieve.
    I don't understand how the GUI, and Card class need to be seperated so that its good OO.
    If I give you a few snippets of code, it might explain the situation:
    A snippet of my card class is as follows:
    Do a quick Google on the model view controller pattern. Your listeners are your controllers. Your JPanel, JButton, etc. are your view. The AI, Player, Card and Deck (and presumably something like Score) are your model. Your model should be completely testable and not dependent on either the controller or the view. Imagine you could play the game from the command line. Get that working first. Then you can add all the bells and whistles for the UI.
    import javax.swing.*;
    public class Card extends JLabel //Each card is a JLabel
    (redacted)
    As you can see, each card is a JPanel. I've been told by some I shouldn't extend JPanel but rather that I should have a BufferedImage/Image instance variable for each card as the image of the card. The thing is that I need each card displayed on the GUI which can then be clickable. When it is clicked, it is moved from the players hand, into the players move. - There needs to be an animation showing this.Extending JPanel is fine. As you noted, you need something to add listeners to. However, I would separate things a bit. First, a card really only has a rank and suit (and perhaps an association to either the deck or a player holding the card). The notion of setIcon() is where you are tripping up. The card itself exists in memory. You should be able to test a card without using a UI. Create a separate class (CardPanel or something similar) that has a reference to a Card and the additional methods needed for your UI.
    I've got the animation code figured out in terms of how to move 'images' around a screen to make a pleasing animation. The problem is there are no clickable listeners for images, so the Images needs to be inside some container; a widget which can fire events - Hence the reason I have chosen to extend JPanel for my Cards.
    and a Deck class, snippet is as follows:
    public class Deck extends JLabel //The deck will be shown on the GUI as a JLabel
         private ArrayList<Card> standardDeck;
         public Deck()
              standardDeck = new ArrayList<Card>();
              ImageIcon cardBack = new ImageIcon("CardBack.png");
              setPreferredSize(new Dimension(90, 135));
              setIcon(cardBack);
              int cardCount = 0;     //This variable counts the cards. Is used to assist in the name generation of the imageicon filename
              String str; //the imageIcon constructor accepts filenames as strings so this string holds the filename of the corresponding card image file.
              for (int a=0; a<4; a++) //putting the cards into the deck with the specifed parameters
                   for (int b=2; b<15; b++)
                        cardCount+=1;     //incrementing the card count (the card files are named 1-52 as integers)
                        str = Integer.toString(cardCount); //Integer is converted to string type before being added to string str variable
                        str += ".png"; //To complete the image filename, ".png" has to be concatenated to the string.
                        standardDeck.add(new Card(b, a, new ImageIcon(str), cardBack)); //creating and then adding the cards
         }This is how I envisage a new class diagram for my game:
    I am not an animation buff, so I will assume the above works.
    Card classRemove the UI aspects to this class, and I think you are all set here.
    Game Class <--- Holds a Deck instance, Players instances, and the GUI instancePresumably this is where main() resides. It will certainly have a reference to model classes (player, game, deck, etc.) and likely the master JFrame (or a controller class you create yourself).
    Player Class <-- Will contains hand 'instances' , but I will not create a seperate 'Hand' Class, I will use an ArrayList.Does a player really have multiple hands? It seems to me more of a one-to-one relationship (or a player has a one-to-many relationship to Card).
    AI Class extends Player ClassWhy extend Player? Create a Player interface, then have a HumanPlayer and AIPlayer implementation. Common parts could be refactored out into either a helper class (delegation) or AbstractPlayer (inheritance).
    GUI ClassMy assumption is that this class has a reference to the master JFrame.
    Deck Class <-- contains 52 cards
    Yes. You may end up recycling this class such that a Deck can also function as a Hand for a given player. If there are differences between the two, create an interface and have a Hand and a Deck implementation. Coding to interfaces is a good thing.
    My question is, how do I show the Cards on the GUI if my Cards are in a Deck and the Deck is held in the Game class?You need to pass a reference to the appropriate view class. That is how MVC works. The controller receives a request from the view, dispatches to some model functionality you write (such as GameRulesEngine, Deck, etc.) and returns a result to the view (which could be the same view or a different one, imagine someone clicking 'high scores').
    Please note that there are 52 cards, so potentially 52 images on the GUI, each of which needs to be clickable. When clicked, the cards are moved about, e.g. from the deck to a players hand, from a players hand back to the deck, from a players hand to a players current move hand.
    etc
    That is up to you to write the animation code. In principle, you have a mouse listener, and then you take the appropriate rendering steps.
    I've read that GUI, program control, and logic should be seperated. If thats the case, what do I have in my GUI class if the Cards (which are JPanels) are held in the Deck class which in turn is held in the Game class?
    See above.
    Any help on this would be greatly appreciated!
    You are welcome.
    I know what I have written may not be fully clear. I find it hard sometimes to fully convey a problem at hand. Please let me know if you don't understand what I've written and I'll do my best to explain further.No, you have been doing fine.
    - Saish

  • Java Card Game (Carioca)

    Hi everyone.
    Im currently making a card game in java for a south american game called Carioca
    originally i had
    CariocaController, which controlled game logic such as creating cards and players, dealing the cards setting the cards etc.
    btnStartGame in GUI would run controller method startGame which would initialize everything then set the GUI.
    CariocaTablelGUI, which extended JFrame and set the game GUI by using swingcomponents (JButtons with ImageIcons for cards)
    Card, like it says, card suit, no and value
    Deck, which created an ArrayList<Card> + 2 jokers.
    Pile which extended ArrayList<Card>. (Used for creating the 2deck game, player hands, putdown pile)
    Ive never been to good with GUI's and not enjoying my inopropriate gui structure i decided to read about java game designs.
    I read OReilly Killer Game Programming in Java chapters 1-13 before it got into 3d java. and not feeling it provided the examples i needed i went back to my old book
    Deitel & Deitel How to program Java Fifth edition. which has a case study of ElevatorSimulation which uses the Model View Controller design pattern.
    I have used this simulation as my guide to reform my code structure as i want to create this game as proffesionally and efficiently as possible.
    Now i have.
    CariocaTable which extends JFrame and in its constructor;
              // instantiate model, view and ,controller
              model = new CariocaModel();
              view = new CariocaPanel();
              controller = new CariocaController(model);
              // register View for Model events
              model.setCariocaListener( view );
              add(view, BorderLayout.CENTER);
              add(controller, BorderLayout.SOUTH);CariocaPanel in it has 4 player panels (4 player max game) which would contain their hands. then a center panel which contains the pickup and putdown piles.
    I am having alot of trouble implementing this pattern to my game (mybe im on the wrong track).
    the controller (in the ElevatorSimulation ) has 2 buttons which executes model method addPerson, thats about all the controller does which rocks my understanding.
    the model implements ElevatorSimulationListener (which extends all needed listeners) and has private variabels for all listeners.
    it then has a setElevatorSimulationListener(ElevatorSimulationListener listener) which is set with the view class.
    i have trouble understanding the communication between controller-view and model-view.. controller has to go threw model to talk to view but model only talks to view through listener methods
    public void lightTurnedOff( LightEvent lightEvent )
    //variable lightListener is the view.
          lightListener.lightTurnedOff( lightEvent );
       }i dont know where all the logic should go. i currently have model with the startGame method which creates players and cards, deals cards etc.
    am i on the right track. am i misunderstanding the design pattern? im sorry for the lengthy post, im having trouble understanding this and would like assistance with my understanding or even refer me to a book or website the would be helpful. if u would like more information please do ask.

    morgalr wrote:
    OK, I'll make a few assumptions and you can correct me if I am wrong on any of them:
    1 - the game is for 1 person to play against the computer
    2 - you may want to expend to multiplayer at some point
    3 - you would like to have the structure of the game as modular as possible to allow changesThank you for replying, yes thats exactly right.
    My approach now is to maintain the same structure as before instead of using the ElevatorSimulation as a guide.
    CariocaController will contain game logic and the static main method, and will update CariocaTable threw set methods.
    i will keep the revamped GUI classes, using what ive learned about using 2d instead of Swing Components, ive created an ImageLoader class which CariocaTable instantiates that loads all images into a hash map. PlayerPanel for each player, each panel contains variable Player, Pile hand, Pile downHand (objective of the game). Mybe i should get rid of the pile variables since the class Player already contains them?
    Its the drawing of the GUI that gets to me. Any other suggestions or ideas?

  • Question - making rummy card game applet

    Hi, I am not sure if this is the right place to be putting this, if not please let me know. I'm trying to make an applet for the card game rummy for my final project for school. I was wondering if I could get some help on how to load a card image from a file and randomizing the images for the deal button or if not that then I am also trying a much simpler way due to time constraints. I was trying to make two arrays of strings: one for the facevalue of the card and another for the suit value, then randomize those and draw a string to the correct places for the dealt hand. I can't seem to get this to work well so far. Any help is greatly appreciated. Here is the code for the basic gui that I have now.
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import java.util.Random;
    import java.lang.*;
    public class CardGame extends Applet implements ActionListener {
         Button Deal;
         Button NewGame;
         Button PutDown;
         Color bgColor;
         Color rectColor;
         Image deck;
         MediaTracker mt;
         CheckboxGroup radioGroup;
         Checkbox radio1;
         Checkbox radio2;
         Checkbox radio3;
         Checkbox radio4;
         Checkbox radio5;
         Checkbox radio6;
         Checkbox radio7;
    **Its hard to tell but the arrays are commented out for now.     
         //String[] faceValue = {"ACE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"};
    //     String[] suitValue = {"CLUBS", "HEARTS", "SPADES", "DIAMONDS"};
         public void init()
              setLayout(null);
              mt = new MediaTracker(this);
              Deal = new Button("Deal");
              NewGame = new Button("New Game");
              PutDown = new Button("Put Down");
              Deal.setBounds(750, 450, 75, 25);
              NewGame.setBounds(750, 475, 75, 25);
              PutDown.setBounds(750, 425, 75, 25);
              add(Deal);
              add(NewGame);
              add(PutDown);
              Deal.addActionListener(this);
              NewGame.addActionListener(this);
              PutDown.addActionListener(this);
              radioGroup = new CheckboxGroup();
              radio1 = new Checkbox(" ", radioGroup, false);
              radio2 = new Checkbox(" ", radioGroup, false);
              radio3 = new Checkbox(" ", radioGroup, false);
              radio4 = new Checkbox(" ", radioGroup, false);
              radio5 = new Checkbox(" ", radioGroup, false);
              radio6 = new Checkbox(" ", radioGroup, false);
              radio7 = new Checkbox(" ", radioGroup, false);
              add(radio1);
              add(radio2);
              add(radio3);
              add(radio4);
              add(radio5);
              add(radio6);
              add(radio7);
              radio1.setBounds(143, 525, 10, 10);
              radio2.setBounds(222, 525, 10, 10);
              radio3.setBounds(301, 525, 10, 10);
              radio4.setBounds(380, 525, 10, 10);
              radio5.setBounds(459, 525, 10, 10);
              radio6.setBounds(538, 525, 10, 10);
              radio7.setBounds(617, 525, 10, 10);
         public void Randomize()
              //this is where I need the help mostly.
         public void Stop()
         public void actionPerformed(ActionEvent evt)
         if (evt.getSource()== Deal)
                   setBackground(Color.green); //test
              else
                   Deal.setLabel("Not there, here!"); //another test
         if(radio1.getState())
                   setBackground(Color.blue); //just a test to make sure I know how to use the radio buttons
         public void paint(Graphics g) {
              g.drawString("Welcome to Rummy!!", 300, 50 );
              g.drawRect(100, 100, 600, 440);
              g.drawRect(110, 420, 75, 100);
              g.drawRect(190, 420, 75, 100);
              g.drawRect(270, 420, 75, 100);
              g.drawRect(350, 420, 75, 100);
              g.drawRect(430, 420, 75, 100);
              g.drawRect(510, 420, 75, 100);
              g.drawRect(590, 420, 75, 100);
              g.drawRect(110, 120, 75, 100);
              g.drawRect(190, 120, 75, 100);
              g.drawRect(270, 120, 75, 100);
              g.drawRect(350, 120, 75, 100);
              g.drawRect(430, 120, 75, 100);
              g.drawRect(510, 120, 75, 100);
              g.drawRect(590, 120, 75, 100);
              g.drawRect(300, 250, 75, 100);
              g.drawRect(380, 250, 75, 100);
              g.drawString("A S", 220, 445);
    }

    thanks for that...could I use something like this for the playing card class though:
    public class Card {
    public final static int SPADES = 0, // Codes for the 4 suits.
    HEARTS = 1,
    DIAMONDS = 2,
    CLUBS = 3;
    public final static int ACE = 1, // Codes for the non-numeric cards.
    JACK = 11, // Cards 2 through 10 have their
    QUEEN = 12, // numerical values for their codes.
    KING = 13;
    private final int suit; // The suit of this card, one of the constants
    // SPADES, HEARTS, DIAMONDS, CLUBS.
    private final int value; // The value of this card, from 1 to 11.
    public Card(int theValue, int theSuit) {
    // Construct a card with the specified value and suit.
    // Value must be between 1 and 13. Suit must be between
    // 0 and 3. If the parameters are outside these ranges,
    // the constructed card object will be invalid.
    value = theValue;
    suit = theSuit;
    public int getSuit() {
    // Return the int that codes for this card's suit.
    return suit;
    public int getValue() {
    // Return the int that codes for this card's value.
    return value;
    public String getSuitAsString() {
    // Return a String representing the card's suit.
    // (If the card's suit is invalid, "??" is returned.)
    switch ( suit ) {
    case SPADES: return "Spades";
    case HEARTS: return "Hearts";
    case DIAMONDS: return "Diamonds";
    case CLUBS: return "Clubs";
    default: return "??";
    public String getValueAsString() {
    // Return a String representing the card's value.
    // If the card's value is invalid, "??" is returned.
    switch ( value ) {
    case 1: return "Ace";
    case 2: return "2";
    case 3: return "3";
    case 4: return "4";
    case 5: return "5";
    case 6: return "6";
    case 7: return "7";
    case 8: return "8";
    case 9: return "9";
    case 10: return "10";
    case 11: return "Jack";
    case 12: return "Queen";
    case 13: return "King";
    default: return "??";
    public String toString() {
    // Return a String representation of this card, such as
    // "10 of Hearts" or "Queen of Spades".
    return getValueAsString() + " of " + getSuitAsString();
    } // end class Card
    except now how would I make something like this random I know theres a bunch of work before that, but just curious. Thanks

  • C# Universal App Unity bad card game render

    Hello,
    I am working on a card game designed in Unity and I am getting some blurry rendering.
    I thought perhaps someone here may know why.
    I only get strange rendering when building for Windows Store and Window Phone.
    Building for Desktop does not have rendering issues.
    Below are links to the rendered output.
    Desktop:
    http://1drv.ms/1GzQ7Qh
    Windows Store:
    http://1drv.ms/186ocZK
    Windows Phone:
    http://1drv.ms/186oi3A
    Why is the Windows Store build blurry?
    Notice that the Windows Phone render has even more problems.
    There appears to be what I think is an antialiasing problem on the right and top edges of the images.
    Notice that the empty hand with the no score disk, has noticeable streaks up and to the right.
    Also notice that the cards have a black rectangle to the right of them.
    I believe this is happening because I do not have a completely transparent border around the png file.
    All images are textures on a Unity plane object.
    The Windows Store and Windows Phone build were created as C# Universal App solution.

    Hi Takimchu,
    If you are asking unity render problem, I would recommend you post your question on unity community forum. This forum is to discuss questions about windows store app.
    http://forum.unity3d.com/.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Create a cross platform online Card Game

    How would I go about creating a cross platform online card game. An example of such an application is one I found where people can play the "Magic the Gathering" card game online and I was wondering how to go about creating a graphic interface where players could upload the images of cards and move them freely around the screen. There would not need to be any rules for the game. It would only need to be able to shuffle a deck and count how many cards are left in the deck and the discard pile.

    I agree just installing the application would be the best option however one of the requirements of this is that it can run from the CD as we are going to be distributing some promotional material in the form of a flash application and would like to have run on either windows or mac without needing to require the users to have to choose the version.

  • What are the Trading Card Games for iPod touch that doesn't requires Internet connection?

    What are the Trading Card Games for iPod touch that doesn't requires Internet connection? Suggestions, please.

    Why not look at the apps and fine out?
    The odds of someone here knowing that are slim to none.

  • HT201272 i have download 120 mb size (uno card game) on my laptop how can i get it on my iphone s4

    i have download 120 mb size (uno card game) on my laptop how can i get it on my iphone s4

    If you downloaded it from the app store on your computer's iTunes then connect your iPhone to your computer and select it on the left-hand side of your computer's iTunes, and then use the Apps tab on the right-hand side of iTunes to select and sync that app to the phone.
    If you downloaded it somewhere else then you won't be able to copy it to your phone - only iTunes apps work on iOS devices, PC and Mac software aren't compatible with them.

  • Can't load masque card games on my laptop

    why can't I load masque card game to my laptop. it said pro mac not supported

    This says the game supports Mac OS 8.1, so I suspect it's a Classic app, which would require a Classic environment, which hasn't been supported by Apple since OS 10.5 or on any Intel Macs.
    http://www.amazon.com/Masque-Card-Games-Mac/dp/B0000C0ZC0

  • Card Game related question

    Hello, I am not sure what forum this goes to or if it goes under any forum, but I was wonder if anyone has a way of taking an array of 7 cards placing an array of 5 cards made from the seven in a hashtable so that it will drop ever possible combination of those cards.
    Or if you have a better way of doing that
    If you are wonder I am making a Texas Holdem style poker game...
    Thank you for any and all help :)

    Start here:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
    Good beginner card game examples there.
    As far as every possible combination, you will probably need a recursive combinations method of some sort.

  • Advice to implement a mouse listener for card game

    Hi,
    I am wondering about the best way to apply a mouselistener in my card game.
    - i only want to listen for 'clicks'
    - I have a JFrame with a JPanel inside. The JPanel has a null layout and many JLabels. The JLabels are the cards, i want to listen for mouse clicks on these 'cards'
    I have seen it is not possible to apply a mouse listener to a JPanel or JLabel so is the most efficient way to apply the listener to the JFrame and then use getComponent () to determine which JLabel has been clicked ? or is there a better way ?
    any thoughts appreciated . .

    hey dubai, thanks for your quick help today, it is much appreciated !
    i know the event should provide a reference to the source, i use the toString to overide the methods in the mouseEvent object and im printing this string to the console. It gives me the correct dimensions within my JPanel of where i clicked but the source is always given as the panel name. Have you any idea why it does not return the name of the JLabel ? I checked out the Action interface, thanks, it cud be very useful to seperate the code by using this.

  • Creating cards for a card game

    So I'm playing with the idea of putting together a simple battle card playing game and am running up against a data/code issue. In the game will be various Cards (potentially hundreds). Each card will have some data describing various its strengths and it may also have complex methods that handle what happens when you play the card.
    (I'd like each Card implementation to represent what the card does, as opposed to who may hold a particular copy of it. For example, I'd like to have a unique JackOfDiamondsCard object that represents info specific to the card. I may then have several Hands that contain CardInstance objects, some of which may have a reference to the unique JackOfDiamondsCard object. Thus the JackOfDiamonsCard could appear in multiple hands.)
    At first glance it's a simple case of having a root Card class and hundreds of children that fill out the details. However, this has the problem that I can create many instances of the same card, which both seems like a waste of memory (since all instances would have exactly the same data) and would make equals() and hashCode() give different results for different instances of the same card.
    One way around this is to put all the cards together into a single enum, but that would quickly grow to an unmanagable (and unreadable) size. I'd also like to be able to group the cards into different packages, or maybe even spread them across several jars.
    Another way may be to turn each card into a singleton and then build an index of all the cards in the jar (maybe using @annotations?) This seems kind of complicated, though, and writing all those singletons would make for a lot of boilerplate in each card class.
    Any ideas on a good way to tackle this? Are singletons the way to go or should I put up with potentially multiple copies of the same card object floating around?

    Mark_McKay wrote:
    The problem is that I need the overriding classes to provide some fairly complex code for each card. In a battle card game, there may be several different things in play that each card could alter in a wacky way. One card may give the player more 'energy points'. Another may strike the opponent with lightning damage. A third may cause one player to randomly steal a card from the other player. A fourth could set up some sort of defense barrier. The wide (and unpredictable) range things that each card may do prevent me from creating just one generic card class. (Although that would work well if the cards only differed by their data).Allow me to introduce some friends of mine. Probably the first one is going to be easiest for you to understand and get working quickly. The last one, probably only any use in conjunction with one of the others here.
    This wacky behaviour is really just another property of the card, like it's suit, or name, or whatever. Behaviours, like data, can often be assigned to objects at runtime, rather than expressed with unweildy inheritance trees.

  • LR not showing all images on card during Import

    I have the latest version of LR.  iMac and Canon 7D.  With my camera tethered directly to my computer, I start the Import Photos process.  When the thumbnails begin to load, it seems like if I have a large amount of photos to import (from 8GB card), it always leaves off the last hundred or two (approximately).  They just don't show up.  I'll import what is visible, then go back and do another import immediately.  All the ones that have been imported show up as greyed out thumbnails, then the remaining images on card will be avavilable for Import.
    Why is Lightroom not seeing all the images the first time??

    Yes it is.
    http://micechat.com/forums/blogs/weekend-update/1532-wizarding-world%3B-toy-stor y-3%3B-main-street-disneyland-hong-kong%3B-classic-revolution.html
    Safari is unable to load any more images, works fine on the desktop, but not on the iPad.

  • What about source code of card-game?

    Who can to show me about source code of card-game that mutilplayer on network according to way client/server?

    How about skipping the source code part and simply going to a store and by a network-based card game? I'm sure there are some. Or Yahoo games or something...
    (Now please don't tell me "you want to create one yourself", because you won't.)

  • Playing online card games such as euchre or spades

    All right here is my problem: I want to play card games online with other users. I'm new to Mac and so far this is my only problem. On my old PC I could go online to pogo.com or anywhere and play a card game no problem. Now I get the room loaded for the game but it's only the outline. There are no users and no tables. Everything is blank. I thought it could be something to do with java, but I'm not sure. I have done software updates, downloaded adobe shockwave and tried numerous different java settings. Any ideas? Am I missing another piece of software?

    What browser are you using? Could be the site is optimized for windows compatible browser. Contact the web site and find out if your browser has issues with their site and which Mac browsers are compatible.

Maybe you are looking for