-4

I want to develop a java graphic application. The concept is that there will be a circle in the middle and several balls will rotate around the circle. Is it possible to make the circle stable forever and only change the position of balls? If it is, how? Also, Is it possible to get a circle or ball like a normal java object?

When I use repaint() method, all of the drawings are repeated. But I do not want to change the location of circle, I only want to change the position of ball that I need.

Thanks.

Talha
  • 1
  • 2
  • Yes it is possible, why not give it a try? You will of course want to separate the logical portion of your program (the location, size and movement of your circles), from the graphical representations portion (the GUI). – Hovercraft Full Of Eels Jun 29 '14 at 18:20
  • 1
    `"When I use repaint() method, all of the drawings are repeated. But I do not want to change the location of circle, I only want to change the position of ball that I need."` -- your code will only do what you tell it to do. To have us help you fix it, you would need to post a small minimal runnable representation of that code. I would draw the un-moving circle on a BufferedImage, one that is drawn in your JComponent's paintComponent method, and then draw your other sprites after your timer code moves them. – Hovercraft Full Of Eels Jun 29 '14 at 18:55
  • 1
    Painting is a destructive process, think of it like a painting onto a canvas, what you paint onto it will cover what was painted before. Regardless of the process you choose, you will always end up having to "reset" the canvas back to some default state before you can continue to update/repaint the content, that's just how it works... – MadProgrammer Jun 30 '14 at 00:32

1 Answers1

0

It is not a game, but you can use a loop of update-render-sleep.

https://www.google.pt/#q=java+game+loop

And as for the fact tht you want to mantain the balls, use math:

  • Where will the center ball be?
  • How much will the radius of the center ball measure?
  • And the others balls? How will they rotate? What is their radius? How many are they?
  • etc..

Answer this and many aothers to yourself, and make a bit of studies in internet.

I hope I could help you.

saclyr
  • 161
  • 5