Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Card Game help....

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Thanked 0 Times in 0 Posts

    Default Card Game help....

    Im back again....

    The: topCards.setLayout(new GridLayout(1, 0)); didnt make the buttons smaller...it stayed the same...

    So, I tryed using a JPanel and flowlayout inside the border layout to make the buttons smaller... and it worked

    But, ive run into another problem...for the card game i want three buttons at the top(north position) and three and the bottom(south position).
    I wrote 3 buttons for each area, with coordinates, but only 1 button shows in each area...

    I looked up BoxLayouts,GridLayouts, CardsLayouts, gridLayouts...ects

    But im still confused on how to make it work...
    Can someone point me towards the right direction...
    OR give me example...

    CODE HERE:________________________________

    import java.awt.BorderLayout;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.LayoutManager;

    import javax.swing.BoxLayout;
    import javax.swing.Icon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class Layout extends JFrame{

    public static void main(String[] args) {

    JFrame frame = new JFrame("UNO"); // sets JFrame to say UNO

    frame.setSize(850, 400); // set width and height of frame

    frame.setLocationRelativeTo(null); // center it in middle
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    LayoutManager border = new BorderLayout(1, 1); // border layout

    //JButton button = new JButton("TOP Cards");

    //__TOp Cards________________________//
    JPanel topCard1 = new JPanel(); // area for card 1
    topCard1.setLayout(new FlowLayout(FlowLayout.RIGHT,620,3));
    topCard1.add(new JButton(" Card1 "));
    frame.add(topCard1, BorderLayout.NORTH); // should i add something here to be able to add mutiple buttons ??

    JPanel topCard2 = new JPanel(); // Area for card 2
    topCard2.setLayout(new FlowLayout(FlowLayout.RIGHT,340,3));
    topCard2.add(new JButton(" Card2 "));
    frame.add(topCard2, BorderLayout.NORTH);

    JPanel topCard3 = new JPanel();
    topCard3.setLayout(new FlowLayout(FlowLayout.RIGHT,220,3)); // Area for card 3
    topCard3.add(new JButton(" Card3 "));
    frame.add(topCard3, BorderLayout.NORTH);

    //___Bottom Cards________________________________//

    //JButton button2 = new JButton("Bottom Cards");
    JPanel bottomCard1 = new JPanel();
    bottomCard1.setLayout(new FlowLayout(FlowLayout.RIGHT,620,3)); // hgap(horizontal), vgap(vertical) used a flowlayout for button
    bottomCard1.add(new JButton(" Card 1 "));
    frame.add(bottomCard1, BorderLayout.SOUTH);

    JPanel bottomCard2 = new JPanel();
    bottomCard2.setLayout(new FlowLayout(FlowLayout.RIGHT,340,3));
    //bottomCards2.setLayout(new BoxLayout(bottomCards2, BoxLayout.Y_AXIS)); // box layout
    bottomCard2.add(new JButton(" Card 2 "));
    frame.add(bottomCard2 ,BorderLayout.SOUTH);

    JPanel bottomCard3 = new JPanel();
    bottomCard3.setLayout(new FlowLayout(FlowLayout.RIGHT,220,3));
    bottomCard3.add(new JButton(" Card 3 "));
    frame.add(bottomCard3, BorderLayout.SOUTH);

    //JPanel content = new JPanel();
    //content.setLayout(new FlowLayout());
    //content.add(new JButton());
    //content.add(new JButton("2"));
    //content.add(new JButton("This is button three"));
    //content.add(new JButton("four"));
    //frame.add(bottomCards, BorderLayout.SOUTH);
    // for each button

    frame.setVisible(true); //

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: Card Game help....

    You can stack layouts, which means you can put a group of buttons in a JPanel with a BoxLayout, then add that JPanel to the north position of another JPanel that has a BorderLayout.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Card Game Problem....Need Help
    By macFs89H in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 28th, 2011, 07:30 AM
  2. help on war card game project
    By sc0field1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 3rd, 2011, 04:51 AM
  3. Credit card validator
    By SOK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2010, 03:11 AM
  4. Card and CardTest
    By etidd in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 29th, 2010, 10:37 AM
  5. my programs- Card and CardTest
    By etidd in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 27th, 2010, 08:06 PM

Tags for this Thread