this is my java code that i'm experimenting with right now. trying to learn graphics.

import java.applet.*;
import java.awt.*;

public class game extends Applet
{
	Image dbz;
	
	public void init()
	{
		Font newFont = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 50);
		setFont(newFont);
		dbz = getImage(getCodeBase(), "dbz.jpeg");
	}
	
	public void paint(Graphics g)
	{
		//Color red = new Color(255,0,0);
		//g.setColor(red);
		//g.drawString("hello world", 50, 50);
		g.drawImage(dbz,0,0,this);
	}
}

and i'm just using a regular html file to run it in. when i compile it i get no errors, but the image never shows. on line 12 i can type anything into the quotes and still get no errors, so i think that might be where the problem is.

Dani AI

Generated

This thread shows an applet that compiles but never renders its image. Likely culprits are: the image file is not where the applet expects (path/codebase mismatch), the load is asynchronous and the image isn’t ready when paint runs, filename case/extension differences on the server, incorrect server MIME or a 404, or the runtime environment (browser Java plugin) blocking the applet. ’s snippet makes the path and load-timing the prime suspects.

A short, practical checklist and a safer load pattern:

  • Confirm the image URL is reachable from the same location the applet uses (open the image URL in a browser to check for 200 vs 404).
  • Remember servers (Linux) are case-sensitive: dbz.jpeg != dbz.JPG.
  • Use a synchronous loader (ImageIO) or a MediaTracker so the image is ready before painting.
  • Check the applet tag’s codebase/document base and ensure the image sits relative to that location.
  • Inspect the Java console for 404/security messages and try appletviewer (if available) to run outside a browser.

A concise ImageIO pattern (synchronous load) that avoids getImage’s async behavior:

BufferedImage dbz;
public void init() {
    try {
        dbz = ImageIO.read(new URL(getCodeBase(), "dbz.jpeg"));
    } catch (IOException e) {
        e.printStackTrace();
    }
}
public void paint(Graphics g) {
    if (dbz != null) g.drawImage(dbz, 0, 0, this);
}

Note: modern browsers have largely removed NPAPI Java plugin support, so applets that worked in older setups may be blocked today. This advice builds on ’s tutorial pointers and echoes ’s hint about the file being missing — the checklist should help isolate whether the problem is path, load timing, or environment.

Recommended Answers

All 2 Replies

Only thing I can really think of is did you add it to something that can show it? My friend had this problem earlier today he just forgot to add.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.