0

I need your helps once again. I have started programming with Java quite recently and I'm trying to create my first applet. I am just using the most basic code:

package firstofthings;

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

public class FirstApplet extends Applet {
    public void paint(Graphics g) {
        g.drawString("This is my first Java applet!", 20, 30);
    }
}

(The curly brackets are put in the right places, wont show up here in right place for some reason)

I am rather proficient in html, and I think it is the code in this container that is wrong, so if you could point me in the right direction that would be quite cool.

<!DOCTYPE html>
<html>
    <head>
        <title>FirstApplet</title>
    </head>
    <body>
        <applet
          codebase="."
          code="FirstApplet.class"
          name="FirstApplet"
          width="640"
          height="480"
          hspace="0"
          vspace="0"
          align="middle"
        >
        </applet>
    <body>
<html>

I took away the tags or else it wouldnt show up, so here is the details of the error I got

ClassNotFoundExeption

Java Plug-in 10.5.1.255
Using JRE version 1.7.0_11-b21 Java HotSpot(TM) Client VM
User home directory = C:\Users\Owner
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
10
  • 3
    Please format your code Commented Feb 17, 2013 at 10:48
  • Please edit your question to make it readable: remove all the code and pseudo-html, paste it back is as-is, no modification, the select each block and press the {} button to mark it as code. Commented Feb 17, 2013 at 10:49
  • 1
    Formatted your question so it was a little more readable. Please use the code ("{}") button in future questions. Commented Feb 17, 2013 at 10:49
  • Thanks I didn't know so I will do that next time. Commented Feb 17, 2013 at 10:51
  • Did you put a file called 'FirstApplet.class' in the same location as the page your are browsing, the codebase="." means 'here'. Commented Feb 17, 2013 at 10:51

1 Answer 1

1

If firstapplet.html (the name of the HTML seen above) is actually at:

http://our.com/applet/firstapplet.html

Then the applet class (as loaded from a loose class file) must be located at:

http://our.com/applet/firstofthings/FirstApplet.class

If the class were in a Jar (highly recommended) or the codebase were set differently, it would change.

Sign up to request clarification or add additional context in comments.

1 Comment

I don't know what that means. I always guessed it was your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.