This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Want to Load an Image  RSS feed

 
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.
 
Ranch Hand
Posts: 15304
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
Ranch Hand
Posts: 15304
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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!