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 8092029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:12:01+00:00 2026-06-05T20:12:01+00:00

Right now I have a function, in a class that is used to listen

  • 0

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.

JInternalFrame obscuring the map

^^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);
    }
}
  • 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-06-05T20:12:02+00:00Added an answer on June 5, 2026 at 8:12 pm

    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.

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

Sidebar

Related Questions

I have a function that adds eventhandlers to control events. Right now I have
Good day! I right now have a function the drags an element from a
I have a one-dimensional function minimizer. Right now I'm passing it function pointers. However
Right now I have something like this in NHibernate: Expression.Like(property, value, MatchMode.Anywhere) and that
Right now i have a line of code, in vb, that calls a text
I have a ListItem class that is used to represent menu items in my
Right now I have this SQL query which is valid but always times out:
Right now I have def min(array,starting,ending) minimum = starting for i in starting+1 ..ending
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
Right now we have AD/Exchange to manage all of our users logins/e-mail on-site at

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.