Hi,
I am new to java programming.

I have been creating a simple applet. Which is as follows:

public class HelloWorld extends JApplet
{
    public void paint(Graphics g)
    {
	g.drawRect(0, 0,getSize().width - 1,getSize().height - 1);
        g.drawString("Hello world!", 5, 15);
    }
}

This code is saved in a file named HelloWorld.Java
I embedded this applet in html as follows:

<applet width=300 height=300 codebase="../../build/classes/applettest/HelloWorld.class"> </applet>

But it doesn't display. Just the java image gets displays ("some sort of progress status type") you know
How can i display this applet.
Please help

Recommended Answers

All 6 Replies

Member Avatar for harsh2327

I suppose your HTML code is incorrect
It should be

<applet width=300 height=300 code="../../build/classes/applettest/HelloWorld.class"> </applet>

if i do this i get the error message as FileNotFoundException. My class file is in different location than the html file so i used codebase instead of code.

when i debug the HelloWorld.java i can output is fine but when i view this in browser it doesn't display.

Hi harsh
I solved the problem.
Thanks for taking interest in my problem anyway.

Member Avatar for harsh2327

wat was the problem
I'd like to know

Yeah, I'd like to know too. Also, if the problem is solved, could you please mark it as solved?
Thanks

The problem was in HTML file while embedding the applet. In the applet tag i had to use both the combination of code and codebase attribute and set it to proper value. I still exactly don't know what is the problem and what is its proper use. But through series of Hit and Trial i just made it worked. The code in the HTML file is as follows:

<applet codebase="../../build/classes" code="applettest/HelloWorld.class" width=350 height=200></applet>

Thanks

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.