Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

Graphics in a Class

Hi,
I'm writing a class that displays an image and can be called from an Applet or something.
Anyway, I have a function setGraphics(Graphics g) which sets a global graphics variable to the parameter passed to it, so it can use the same drawing area as the Applet.
It then sets the image using this code:
BObject=Toolkit.getDefaultToolkit().getImage("somefile.jpg");
and then uses the graphics object to draw it:
grObject.drawImage(BObject, 10, 10, this);
But I get a Cannot Resolve Symbol error and I'm not sure why - the documentation says that drawImage is part of the Graphics class.
Am I mising an import or something? I have the following imports:
import java.awt.*;
import java.applet.*;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.*;

Any help would be appreciated.
0
samwaters
Asked:
samwaters
  • 2
  • 2
1 Solution
 
objectsCommented:
can you post the complete error message
0
 
objectsCommented:
does the class making the call implement ImageObserver?

try:

grObject.drawImage(BObject, 10, 10, null);
0
 
samwatersAuthor Commented:
It said
cannot resolve symbol - method drawImage (java.awt.Image,int,int,ImageClass1)
0
 
samwatersAuthor Commented:
yes apparerntly putting null as ImageObserver keeps it happy - thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now