I was recently trying to use getImage in a class inside of one of my packages. It was giving me a few errors that I didn't understand, I did some googling, found something that said I could only use getCodeBase() in the main top java file. That doesn't make much sense to me, but I tried it and it doesn't throw that particular error now.
so I've imported java.net.* and declared a URL type variable named codeBase in init() I initialized it as codeBase = getCodeBase()
Then, using my new-found referencing powers I slid the codeBase into the call of my other class and then tried to call it as getImage(codeBase, "/tiles/grass1.gif";
The above line produces the error cannot find symbol : method getImage(java.net.URL,java.lang.String)
Which doesn't make any sense to me as here(http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html) it seems to say that there is a constructor for getImage(URL, String)
I have imported
import java.applet.*;
import java.awt.*;
import java.util.zip.*;
import java.io.*;
import java.net.*;
If the above isn't enough, and you feel like digging through my code, here it is, the main class called RPG(Note: I have trimmed my methods such as paint and update and the mouse and keylistener methods as they have no relevance here):
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import components.*;
public class Rpg extends Applet implements Runnable, KeyListener, MouseListener
{
Thread t;
int i, width, height;
URL codeBase;
Font Font15 = new Font("Helvetica", Font.PLAIN, 15);
Image bgImage;
Graphics bg;
Map map;
Player player;
public void init()
{
t = new Thread(this);
t.start();
addKeyListener(this);
addMouseListener(this);
i = 0;
width = getWidth();
height = getHeight();
bgImage = createImage(width, height);
bg = bgImage.getGraphics();
setBackground(Color.black);
codeBase = getCodeBase();
player = new Player(50, 50, width, height);
map = new Map(10, 10, player, codeBase);
player.MapReference(map);
map.SaveArray(map.fileName, map.tileArray);
}
}
And my Map class(also trimmed of non-relevance):
package components;
import java.applet.*;
import java.awt.*;
import java.util.zip.*;
import java.io.*;
import java.net.*;
public class Map
{
int xTilesDraw, yTilesDraw, viewX, viewY, x, y, tileX, tileY, i1, i2;
public String fileName;
public int[][] tileArray;
Dimension tileSize;
Point viewOrigin;
Player player;
public Map(int xDraw, int yDraw, Player player, URL codeBase)
{
xTilesDraw = xDraw;
yTilesDraw = yDraw;
this.player = player;
viewX = player.x-(xTilesDraw/2);
viewY = player.y-(yTilesDraw/2);
tileSize = new Dimension(32, 32);
tileX = xTilesDraw * tileSize.width;
tileY = yTilesDraw * tileSize.height;
fileName = "test";
tileArray = new int[9][9];
i1 = 0;
i2 = 0;
while(i2 < 10)
{
if(i2 > 9)
{
i2 = 0;
i1++;
}
tileArray[i1][i2] = getImage(codeBase, "tiles/grass1.gif");
i2++;
}
viewOrigin = new Point(viewX, viewY);
}
}
I suspect that my filepath in the getImage statement may have something to do with it, my filepath is new_folder(where the rpg is located)/components/tiles
Thanks in advance for any help,
Farshief