Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to Load an Image

 
Juan Ignacio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to load an image into Image type variable for the past 2 days a get to here.

import java.awt.*;
import java.net.URL;
import java.applet.Applet;

public class Board{
//Internal Col
URL url = new URL("c:/Image/board.gif");
Image pict;
//Class Contructor
public Board(){
pict = getImage(url);
}
//an a few methods in here.
}

the error that i'm getting is:
The Method getImage(URL) is undefined for the type Board

Probably I'm missing something in the beginning, like importing something
if anyone knows which package a should import please tell me.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getImage() method does not exist in the class Board. That's why you are getting that exception. Since you've imported the Applet class I'll assume that's what you are trying to make. getImage() is a method of the Applet class so have Board extend Applet and try again.

Moving this to the applets forum...
 
Juan Ignacio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now is the part in Bold the one not working, when I add the "extends Applet"
to my class, I lost the import java.net.URL, why is that, there is a way to solve this?

package classes;

import java.awt.*;
import java.net.URL;
import java.applet.Applet;

public class Persona extends Applet {
//Colaboradores Internos
URL url = new URL("c:/Imagen/placa.gif");
Image foto;
String nombre;
String apellido;
String sector;
String cargo;
String horaEntrada;
String horaSalida;
char estado;
Time fyHActual = new Time();
//Contructor
public Persona (){

nombre = "Juan";
apellido = "Tibaldi";
sector = "Sistemas";
cargo = "Soporte Tecnico de Distrito Sur";
horaEntrada = fyHActual.now();
horaSalida = fyHActual.now();
estado = 'V';
foto = getImage(url);


}
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Juan Ignacio:
Now is the part in Bold the one not working, when I add the "extends Applet"
to my class, I lost the import java.net.URL, why is that, there is a way to solve this?


Yea, retype it?
 
Juan Ignacio
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's do it simple anyone knows how to load an image in java.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic