duda con getDocumentBase()

01/10/2004 - 14:49 por Lorena | Informe spam
A ver si me podeis ayudar, porque me da un error en el
metodo getDocumentBase(), no encuentra la imagen, y no
entiendo por qué.
El programa es el siguiente:

public class Principal extends Applet {
Image bicho;

public Principal(){
init();
}

public void init ( ) {
bicho = getImage(getDocumentBase ( ), "bicho.gif");
}
public void paint (Graphics g) {
g.drawImage (bicho, 25, 25, this);
}

public static void main(String[] args) {
Principal principal1=new Principal();
}

}

Y bicho.gif esta en el mismo directorio donde esta la
carpeta class de mi proyecto.
¿Donde esta el error?
Muchas gracias
 

Leer las respuestas

#1 Patxi Sanz
03/10/2004 - 16:03 | Informe spam
Hola Lorena:

getDocumentBase() devuelve la url del documento html donde incrustas el
applet. Para conocer la ruta del applet, debes usar getCodeBase().

- Info sacada de la ayuda sobre Java en http://java.sun.com

getDocumentBase

public URL getDocumentBase()
Gets the URL of the document in which this applet is embedded. For
example, suppose an applet is contained within the document:
http://java.sun.com/products/jdk/1.2/index.html

The document base is:
http://java.sun.com/products/jdk/1.2/index.html

Returns:
the URL of the document that contains this applet.
See Also:
getCodeBase()



getCodeBase

public URL getCodeBase()
Gets the base URL. This is the URL of the directory which contains this
applet.
Returns:
the base URL of the directory which contains this applet.
See Also:
getDocumentBase()

Un saludo,



Patxi Sanz


"Lorena" escribió en el mensaje
news:21bd01c4a7b5$19c0a030$
A ver si me podeis ayudar, porque me da un error en el
metodo getDocumentBase(), no encuentra la imagen, y no
entiendo por qué.
El programa es el siguiente:

public class Principal extends Applet {
Image bicho;

public Principal(){
init();
}

public void init ( ) {
bicho = getImage(getDocumentBase ( ), "bicho.gif");
}
public void paint (Graphics g) {
g.drawImage (bicho, 25, 25, this);
}

public static void main(String[] args) {
Principal principal1=new Principal();
}

}

Y bicho.gif esta en el mismo directorio donde esta la
carpeta class de mi proyecto.
¿Donde esta el error?
Muchas gracias

Preguntas similares