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

  • Home
  • SEARCH
  • 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 124825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:03:42+00:00 2026-05-11T05:03:42+00:00

I am developing a simple platform game using Java using BlueJ as the IDE.

  • 0

I am developing a simple platform game using Java using BlueJ as the IDE. Right now I have player/enemy sprites, platforms and other items in the game drawn using polygons and simple shapes. Eventually I hope to replace them with actual images.

For now I would like to know what is the simplest solution to setting an image (either URL or from local source) as the ‘background’ of my game window/canvas?

I would appreciate it if it isn’t something long or complex as my programming skills aren’t very good and I want to keep my program as simple as possible. Kindly provide example codes with comments to elaborate on their function, and also if it’s in its own class, how to call on relevant methods used by it on other classes.

Thank you very much.

  • 1 1 Answer
  • 2 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. 2026-05-11T05:03:43+00:00Added an answer on May 11, 2026 at 5:03 am

    The answer will vary slightly depending on whether the application or applet is using AWT or Swing.

    (Basically, classes that start with J such as JApplet and JFrame are Swing, and Applet and Frame are AWT.)

    In either case, the basic steps would be:

    1. Draw or load an image into a Image object.
    2. Draw the background image in the painting event of the Component you want to draw the background in.

    Step 1. Loading the image can be either by using the Toolkit class or by the ImageIO class.

    The Toolkit.createImage method can be used to load an Image from a location specified in a String:

    Image img = Toolkit.getDefaultToolkit().createImage('background.jpg'); 

    Similarly, ImageIO can be used:

    Image img = ImageIO.read(new File('background.jpg'); 

    Step 2. The painting method for the Component that should get the background will need to be overridden and paint the Image onto the component.

    For AWT, the method to override is the paint method, and use the drawImage method of the Graphics object that is handed into the paint method:

    public void paint(Graphics g) {     // Draw the previously loaded image to Component.     g.drawImage(img, 0, 0, null);      // Draw sprites, and other things.     // .... } 

    For Swing, the method to override is the paintComponent method of the JComponent, and draw the Image as with what was done in AWT.

    public void paintComponent(Graphics g) {     // Draw the previously loaded image to Component.     g.drawImage(img, 0, 0, null);      // Draw sprites, and other things.     // .... } 

    Simple Component Example

    Here’s a Panel which loads an image file when instantiated, and draws that image on itself:

    class BackgroundPanel extends Panel {     // The Image to store the background image in.     Image img;     public BackgroundPanel()     {         // Loads the background image and stores in img object.         img = Toolkit.getDefaultToolkit().createImage('background.jpg');     }      public void paint(Graphics g)     {         // Draws the img to the BackgroundPanel.         g.drawImage(img, 0, 0, null);     } } 

    For more information on painting:

    • Painting in AWT and Swing
    • Lesson: Performing Custom Painting from The Java Tutorials may be of help.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 197k
  • Answers 197k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would suggest using a modal view controller for the… May 12, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer An excellent article related to this topic is Member Function… May 12, 2026 at 7:19 pm
  • Editorial Team
    Editorial Team added an answer Yes this does seem a bit clumsy but I can't… May 12, 2026 at 7:19 pm

Related Questions

I am developing a simple platform game in Java using BlueJ. Over the next
I am developing a Flex-based game, and struggling with SmartFox Server. Anyway, it's a
I have been researching around trying to find the best way to begin developing
I've recently started to learn C++ and am completely confused with the choices of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.