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 3 of 3

Thread: Rush Hour Game

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Rush Hour Game

    I am creating the rush hour game. I am using the cars and trucks as Jlabel. I have created a 6x6 grid using GridLayout and I need to place the cars or trucks into the grid. I know how to place into a grid a Jlabel that takes only one cell. But how do you place a Jlabel that takes up more than one cell? For example, the cars occupy two cells on the grid, and the trucks 3 cells


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Rush Hour Game

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Each cell of the grid is an area that can contain only one component, so the concept you've described is not possible. However, you can create the illusion of a single object spanning multiple cells by using colors and modifying the borders between the occupied cells.

    An alternative is to "draw" the vehicles as graphics objects on a paintable object, placing them using a coordinate system. Yes, it's a bit more complicated than the design you've described, but I believe in the end will provide a more satisfactory result.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Viola123 (June 4th, 2014)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Rush Hour Game

    Take a look at the GridBagLayout. Its API doc says: each component occupying one or more cells
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Viola123 (June 4th, 2014)

Similar Threads

  1. Replies: 1
    Last Post: April 21st, 2014, 04:39 PM
  2. Problem to get hour and minute
    By sassa44000 in forum Android Development
    Replies: 9
    Last Post: March 30th, 2014, 09:56 AM
  3. URGENT! Due in one hour. Please help!
    By imanoob in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 10th, 2013, 11:25 AM
  4. Replies: 4
    Last Post: February 20th, 2013, 09:26 AM
  5. Rush hour game
    By zerocos in forum What's Wrong With My Code?
    Replies: 46
    Last Post: January 25th, 2013, 06:05 PM