Advertisement Jump to content
Sign in to follow this  

Anyone know Java applet : loading image

This topic is 3333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to load in a image for my background. I am using Applets. Here is the main class :
import javax.swing.*;
import java.awt.BorderLayout;

public class SceneApplet extends JApplet
	private static final long serialVersionUID = 7916561614273085646L;

	public void init()
		//The image is in the same directory
		BackgroundPanel _background = new BackgroundPanel(this,"background.jpeg");

Here is the BackgroundPanel class :

import javax.swing.*;

public class BackgroundPanel extends ImageLoader
	private static final long serialVersionUID = 7187743368103472006L;	

	public BackgroundPanel(JApplet applet, String imagePath)

And here is the ImageLoader that BackgroundPanel extends from :
import javax.swing.*;
import java.awt.*;

public abstract class ImageLoader extends JPanel
	private Image _image;
	private String _filePath;
	private int _width;
	private int _height;
	public ImageLoader(String filePath){
	public ImageLoader(String filePath, int width, int height){
		_filePath = filePath;
		_image = new ImageIcon(_filePath).getImage();
	public void setImageSize(int width, int height){ 
		_width = width;
		_height = height;
	public void setImageWidth(int newWidth){ _width  = newWidth; }
	public void setImageHeight(int newHieght){ _height = newHieght; }
	public int getImageWidth(){ return _width; }
	public int getImageHeight(){ return _height; }
	public void setNewImage(String filePath){ 
		_filePath = filePath;
		_image = new ImageIcon(_filePath).getImage();
	public String getImagePath(){ return _filePath; }
	public Image getImage(){ return _image; }
	//overriding the draw method
	public void paint(Graphics brush){		

The problem is that the image does not show up. The applet is just gray. Is it a size problem ( size of the image ? ). The image is of type jpeg. I use eclipse as an IDE.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!