0

so I am making a basic framework for a card game application (ex. blackjack, 21, solitaire, caravan) and I need to be able to display card images in groups that overlap and I need a grid system so I can easily set up the places where the "piles" go depending on the game. I'd like to avoid absolute layout if possible. this is what I have so far:

public void displayPanel(){
        JFrame frame = new JFrame("Cards");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setBackground(Color.GREEN);
        frame.setLayout(null);
        frame.add(new JLabel(new ImageIcon("reasorce/Cards/39.png")));
        frame.pack();
        frame.setVisible(true);
    }
  • You should look at GridLayout and GridBagLayout. Also, you don't actually need to overlap images. You need to create the illusion of overlapping images by drawing an image of the edges of several cards (like a drop shadow) and the image of an actual card on top of that. – MarsAtomic May 07 '15 at 02:10
  • Maybe GridBagLayout. – user253751 May 07 '15 at 02:10

1 Answers1

2

I need to be able to display card images in groups that overlap

You can use the Overlap Layout which supports this feature.

So you can have different panels with different OverlapLayouts for the cards. You would then need another layout to manage the different piles of cards. Don't know the exact layout you are trying to achieve so I can't help here.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • kind of like this http://imgur.com/vhW3KMW – Noah Sanders May 07 '15 at 02:39
  • Yes, I gave you the answer to the overlapping of cards. For the board layout you can use a GridBagLayout, or nest panels using different layouts. Read the Swing tutorial on [Layout Managers](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html) for more information and examples. – camickr May 07 '15 at 03:28