Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6747509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:27:08+00:00 2026-05-26T12:27:08+00:00

I was trying to make a board game in java and i am stuck

  • 0

I was trying to make a board game in java and i am stuck with the following problem.

I want to create a object that can be painted in the jpanel. Let’s name this object Board. This board i want it to be a composite object of other boards. Hence when i call the (let’s call it) paint() method of the board , in order to be correctly painted it will have to call paint it self and also call the paint() methods of its sub-boards etc.
I know this is like an already implemented behavior (someone could say.. just make a Jpanel in a Jpanel) but the difference is that for the board object i want to be able to drag/ drop it anywhere in the Jpanel. Plus, the Jpanel may contain many boards which could be dragged/dropped anywhere in it (the can also overlap). So this kind of behavior restrict me from using Java swing components because they all use layouts which is not what i want.

Finally when i add a board object to a board the coords i use want to be relative to the parent board and not to the Jpanel’s. (i.e when i add a board B to the board A, and i want to add the board B to (x,y)=(10,10) , these coords are relative to the location of A )

Is this any way to do it? I ‘m not looking for complete example, just for general ideas (preferable clean!)

PS . i have implemented something that almost works. The problem in my implementation is that Graphics g , class Board uses to be painted is taken from the JPanel, and the x,y coords are relative to the JPanel for all the Boards (and not the the parent board in case the board is added to a parent board and not directly to JPanel).

i don’t know if this is fusible but i am imaging that the leaf board is acutally painting it self with starting coords (0,0) which somehow in the JPanel are traslated to (x,y) depending on the actual location in the Jpanel of the board.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:27:09+00:00Added an answer on May 26, 2026 at 12:27 pm

    I think you could consider using MovingWindows and ResizingComponents. I did something similar in the past using a null LayoutManager but this is a bad idea.

    There are several problems when you need to absolute positioning Components or explicitly set their size.

    Here’s some 2 threads you might consider intersting:

    1. The first discussing a similar problem.
    2. The second explains why you can’t directly use setXXXSize methods on Component.

    The key for understanding those solutions is that you should never set from the application code, the size of your components. If you need to resize something you have to do that on frames.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a board game in Java using AWT. I want
I am trying to make a turn-based board game that will be run on
Trying to make a make generic select control that I can dynamically add elements
I am trying to make a chess game. So I am placing the board,coins
Im trying to create a board game generator in ruby which takes images from
The problem is that I am trying to make certain tiles blocked so the
My problem is I'm trying to make a console based chess game. Starting off
I'm trying to make some web-based board games, and I want the interface to
I'm trying to make a word puzzle game, and for that i'm using a
(Disclosure: I'm very new to Rails) I am trying to make a RISK-style board-game

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.