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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 2 of 2

Thread: Card Game Problem....Need Help

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

    Question Card Game Problem....Need Help

    Hey im new to this website....

    Im making a Uno card game in java as an application(not an applet), my first challenge is figuring out what layout
    i will be using. I decided to use the Border layout, since it deals with the directions: North,South,East,West. This is the layout and the positioning as planned: player 1 (north,top of the screen),player 2(bottom, south of the screen),and deck of cards (east, side of screen).


    this is where i have my problem, I want to display each Unocard as a JButton, so when i click it, it is played.....
    when I use a boarder layout alone, the Jbuttons are too big, i need the buttons to be smaller individual buttons ... what can i do to change this.

    Please be specific, im pretty much starting from ground zero, with the layout first.
    Be specific please....
    Examples or anything would help...

    import javax.swing.*;
    import javax.swing.JFrame;
    import java.awt.*;
     
     
     
    public class Layout {
     
    public static void main(String [] args){
     
    JFrame frame = new JFrame("UNo"); // sets JFrame to say UNO
     
    frame.setSize(600 ,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
    frame.setLayout(border);
     
    JButton button = new JButton("click"); // button text // Just a test
     
     
     
    frame.add(button, BorderLayout.NORTH); // Jbutton is too big, need it be smaller
    //for each button
     
    frame.setVisible(true); // 
     
     
    }
     
    }


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

    Default Re: Card Game Problem....Need Help

    We can't really be specific, because you weren't very specific. You say you want the players at the North and South positions, but then you add only one JButton- doesn't a player have several cards?

    Chances are you want to nest layouts- use a JPanel with, say, a BoxLayout, to display all of the JButtons, then put that JPanel in the North position of another JPanel that has a BorderLayout.

    Recommended reading: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    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. Credit Card Problem (While and Switch will be used)
    By odun in forum Object Oriented Programming
    Replies: 3
    Last Post: March 29th, 2011, 12:54 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. video game problem - delay in response to arrow key presses
    By gib65 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 17th, 2010, 07:39 PM
  4. simple game with swing and awt problem
    By Pulse_Irl in forum AWT / Java Swing
    Replies: 2
    Last Post: October 12th, 2010, 02:04 PM
  5. [SOLVED] minesweeper game creation problem
    By kaylors in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 27th, 2009, 04:06 PM

Tags for this Thread