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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:59:09+00:00 2026-05-25T10:59:09+00:00

How do you set a background image in Java Applets? Let’s say I want

  • 0

How do you set a background image in Java Applets?

Let’s say I want background.gif to be the background in my java applet class but how would I do this?

  • 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-05-25T10:59:09+00:00Added an answer on May 25, 2026 at 10:59 am

    I dont think there is a function to do this. But you can extend a Panel (which can act as a simple container of components) and override the paint method to draw an image in the background.

    The following is a sample program. Hope this helps.

    import java.applet.*;
    import java.awt.*;
    import java.net.*;
    import java.io.IOException.*;
    
    public class BackgroundApplet extends Applet {
         Image backGround;
    
         public void init() {
    
              // set the size of the applet to the size of the background image.
              // Resizing the applet may cause distortion of the image.
              setSize(300, 300);
    
              // Set the image name to the background you want. Assumes the image 
              // is in the same directory as the class file is
              backGround = getImage(getCodeBase(), "save.GIF");
              BackGroundPanel bgp = new BackGroundPanel();
              bgp.setLayout(new FlowLayout());
              bgp.setBackGroundImage(backGround);
    
              // Add the components you want in the Applet to the Panel
              bgp.add(new Button("Button 1"));
              bgp.add(new TextField("isn't this cool?"));
              bgp.add(new Button("Useless Button 2"));
    
              // set the layout of the applet to Border Layout
              setLayout(new BorderLayout());
    
              // now adding the panel, adds to the center
              // (by default in Border Layout) of the applet
              add(bgp);
         }
    }
    
    class BackGroundPanel extends Panel {
         Image backGround;
    
         BackGroundPanel() {
              super();
         }
    
         public void paint(Graphics g) {
    
              // get the size of this panel (which is the size of the applet),
              // and draw the image
              g.drawImage(getBackGroundImage(), 0, 0,
                  (int)getBounds().getWidth(), (int)getBounds().getHeight(), this);
         }
    
         public void setBackGroundImage(Image backGround) {
              this.backGround = backGround;    
         }
    
         private Image getBackGroundImage() {
              return backGround;    
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set a background image for a div, in a way that
like this gif image it has transparent background, when i using ImageIO.write(image,jpg, file) to
I want set the background image for cell. I have already set the background
I have this code to set the background image of the UITableViewController: self.tableView.backgroundColor =
I would like to set background image or a list item when selected or
I set a background image to a layout via the android:background property. I want
This is driving me nuts. I am trying to set a background image to
I have set a canvas' background to an image of a company logo. I
I have a JPanel for which I set some image as the background. I
We need to set background image of a table. One way is to set

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.