Right now I have a function, in a class that is used to listen to my server, that draws my game map based off of a piped file:
String[] mapSplit = map.split("\\|");
mapWidth = Integer.parseInt(mapSplit[0]);
mapHeight = Integer.parseInt(mapSplit[1]);
String[] groundLayer = mapSplit[2].split(", ");
String[] buildingLayer = mapSplit[3].split(", ");
String[] objectLayer = mapSplit[4].split(", ");
int count = 0;
logger.info("Drawing started.");
for (int x=0; x<mapWidth; x++){
xDraw = 0;
for (int y=0; y<mapHeight; y++){
if (!groundLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + groundLayer[count] + ".png").draw(m.gamePanel.getGraphics(), xDraw, yDraw);
}
if (!buildingLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + buildingLayer[count] + ".png").draw(m.gamePanel.getGraphics(), xDraw, yDraw);
}
if (!objectLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + objectLayer[count] + ".png").draw(m.gamePanel.getGraphics(), xDraw, yDraw);
}
xDraw += 32;
count++;
}
yDraw += 32;
}
logger.info("Drawing done.");
This is all fine and dandy. Right now I don’t have a gameloop as I am working on a client/server protocol so it only draws once(when the character is selected and login is done). My problem comes when the jrame the jpanel sits in is resized, or when any of my jinternal frames move over the jpanel.
When the JFrame is resized the entire map disappears.
When the JInternalFrames are moved over the JPanel the map is removed where the overlap occurs.
I am pretty sure this is due to a repaint being called by AWT(from some looking around I did before posting here), but I am unable to get a solution.
Prettymuch I don’t want my JPanel(map) to be cleared/erased/edited unless I choose to update it. This should include, other components being dragged on it, window being minimized, another (windows)application covering part/all of the JFrame, etc.. Any help with this would be greatly appreciated.

^^above is an example of what I meant by dragging a JInternalFrame removes the parts you drag over^^
EDIT
I wanted to post my solution that Stefan Haustein helped me come to!!!
in my main class I made the image:
gamePanelImage = new BufferedImage(gamePanelWidth, gamePanelHeight, BufferedImage.TYPE_INT_ARGB);
gamePanel = new MapGamePanel();
in my server command listener:
logger.info("Drawing started.");
for (int x=0; x<mapWidth; x++){
xDraw = 0;
for (int y=0; y<mapHeight; y++){
//m.gamePanel.getGraphics()
if (!groundLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + groundLayer[count] + ".png").draw(MyClient.getGamePanelImage(), xDraw, yDraw);
}
if (!buildingLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + buildingLayer[count] + ".png").draw(MyClient.getGamePanelImage(), xDraw, yDraw);
}
if (!objectLayer[count].equals("0")){ //don't draw full transparent tiles
SpriteStore.get().getSprite("images/tiles/" + objectLayer[count] + ".png").draw(MyClient.getGamePanelImage(), xDraw, yDraw);
}
xDraw += 32;
count++;
}
yDraw += 32;
}
logger.info("Drawing done.");
and finally the class I used to override JPanel:
package com.jayavon.game.graphics;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import com.jayavon.game.client.MyClient;
public class MapGamePanel extends JPanel {
private static final long serialVersionUID = 1L;
public MapGamePanel() {
super();
setLayout(new BorderLayout());
setBorder(BorderFactory.createLineBorder(Color.black));
}
protected void paintComponent(Graphics g) {
g.drawImage(MyClient.getGamePanelImage(), 0, 0, null);
}
}
Do you override paint(Graphics) and do the drawing in paint(Graphics)?
If not, that is probably the problem.
See “The Paint Method” here: http://java.sun.com/products/jfc/tsc/articles/painting/index.html
If you want to avoid repainting the map in paint() (or paintComponent()), draw the map to a BufferedImage (using getGraphics on the image) when you receive the server data. In paint() just draw your buffer image.