954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

i don't think i'm doing this right. trying to display an image in an applet

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.

JellyTurf
Newbie Poster
11 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

http://download.oracle.com/javase/tutorial/uiswing/components/icon.html
http://download.oracle.com/javase/tutorial/2d/images/loadimage.html
If you are writing a real-world application, it is likely (and recommended) that you put your files into a package.

quuba
Posting Pro
573 posts since Nov 2008
Reputation Points: 123
Solved Threads: 106
 

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.

ProgrammerAl
Light Poster
34 posts since Dec 2010
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: