I'm having a problem painting a background on a JPanel. I have the following written:
Code:
public class ImageBackgroundPainter implements IBackgroundPainter {
private Image _image;
public ImageBackgroundPainter(Image img) {
_image = img;
}
public void init(JComponent comp) {
comp.setSize(_image.getWidth(comp), _image.getHeight(comp));
}
public void paint(JComponent comp, Graphics g) {
System.out.println("Painting..."+_image);
g.drawImage(_image, 0, 0, comp);
}
}
public class HotSpotPanel extends JPanel {
private IBackgroundPainter _background;
public HotSpotPanel(IBackgroundPainter background) {
super(true);
_background = background;
initComponents();
}
public void paint(Graphics g) {
super.paint(g);
_background.paint(this,g);
paintComponents(g);
}
protected void initComponents() {
}
}
I'm working in an Applet and I'm calling getImage() to get the image. I get the message saying "Painting..." but the JPanel is still all gray. Does anyone have any ideas why this wouldn't work? Thanks a lot.
06-27-2005, 06:19 PM
evlich
I tracked my problem back to getting the image. Apparently it wasn't loaded properly. Anyone know what is wrong with this code:
Code:
public class WebApplet extends JApplet {
private MediaTracker _tracker;
public void init() {
_tracker = new MediaTracker(this);
new SimController(getParameter("classpath"), getParameter("startroom"), this.buildResourceAdapter());
}
}
I am using "file://" since the image is on my hardrive, for the time being. Any help would be greatly appreciated.