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.