Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Drawing circles on a JPanel with an image already on it?

794365Oct 7 2009 — edited Oct 8 2009
I have a program in which I want to display the players' current positions on a map by drawing ovals around each of their pixel coordinates (x,y).

Inside my GameWindow class (a JFrame with multiple panels), I've created a JPanel named "map" as GameWindow class variable (in order for other classes to be able to access it), and created an ImagePanel class inside GameWindow that overrides the JPanel paintComponent and draws the map on the panel. I then assign "map" to a new ImagePanel (which is then added to the frame).

The problem is that the players' positions are maintained by a seperate class called GameRunner. I tried to add a method like...

void drawPlayerOvals (Graphics g, int x, int y)
{
   g.drawOval(x-3, y+3, 9, 9);

}
...inside the ImagePanel class. I was thinking that since my GameRunner takes in a GameWindow "w", I could create a Graphics class variable "graph" inside GameRunner and call something like:

w.mapPanel.drawOval(graph, playerXcoordinate, playerYcoordinate)
for each player position. The compiler wouldn't let me do this, however.

I was wondering why exactly the compiler wouldn't allow this, and what exactly would be the best way to display these circles on the map?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2009
Added on Oct 7 2009
7 comments
501 views