i am trying to load images for an applet using imageicon but i found out that it doesnt work so i was wondering if there is other way to load em. by the way i am trying to load them in another class that is not the main one. this is the code:
i am using an imageicon to load an image and store it in an array of images since i cant use getDocumentBase() for a reason that i do not know. in the appletviewer works fine but when i try to see it in a webpage it doesnt show any of the images . can someone suggest me what to do?

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;

import javax.swing.ImageIcon;


public class Map {
MainGame GameMode;

public Image MapArray[]=new Image[1000];
public ImageIcon img;
public int NumberOfImages;
public int Pause;
public int p;
File file[]=new File[1000];
boolean exists[]=new boolean[1000];
public int IndexRight[]=new int[1000];
TimerDemo t;
Map(MainGame GameMode){
this.GameMode=GameMode;
t=new TimerDemo(GameMode);
}
public void LoadMap(String Directory,String Ext,int NumberOfImages,int Pause){
	this.NumberOfImages=NumberOfImages;
	this.Pause=Pause;
	for(int i=0;i<NumberOfImages;i++){
	
		if(i<=8){
	img=new ImageIcon(Directory+"00"+(i+1)+Ext);
		}else if(i>=9 && i<=98){
	img=new ImageIcon(Directory+"" +
			"0"+(i+1)+Ext);		
		}else{
	img=new ImageIcon(Directory+(i+1)+Ext);		
		}
	MapArray[i]=img.getImage();
	}
}
public Image ReturnMapIndex(){

	Image imaging=MapArray[GameMode.MapIndex];
	if(GameMode.UP){
	if(p>Pause){
	p=0;
	GameMode.MapIndex++;
	imaging=MapArray[GameMode.MapIndex];
	}else{
	p++;
	}
	}
	if(GameMode.DOWN){
		if(p>Pause){
			p=0;
			if(GameMode.MapIndex==0){
				
			}else{
			GameMode.MapIndex--;
			}
			imaging=MapArray[GameMode.MapIndex];
			}else{
			p++;
			}
	}
	return imaging;
	
	
}
public void DrawMap(Graphics g){
	
	
	g.drawImage(ReturnMapIndex(),1,1,null);
	if(GameMode.ZOMBIE.Zposition==2){
	t.start();
	t.Draw(g);
	}
}

	
}

thanks in advance.

Where are the images you are trying to load? Are they in the same folder as the class file or in some other folder on your PC. Applets are NOT allowed to go to any folders on your PC. They can read files from the folder that they are loaded from.
Look at using a URL with the ImageIcon constructor vs a String

it is in the same jar file in a different folder where i keep all the images. but with an url would it make it slower to load the images since i will be reading them from the internet and is quite a lot of pictures

If the images are all in the jar file with the applet's class files, then you need to treat them as resources and use the classloader to access them.
See the Class class's getResource methods.

I see, thanks Norm, i already fixed it and it is now working. but i have another question how can i load music from another class that is not the main applet?

I guess that you'd use the same technique from any class loaded from the jar file to read any file that is in the same jar file as the applet class files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.