I am just starting to learn Java (woohoo!!) and I'm reading a book called Introduction to Programming Using Java.
The book has some examples, for instance, on how to create applets, I've been trying to do it myself to no success, even after try to copy their example, it still doesn't work. I write the class and compile it, then I copy the class to the same folder as my html file and state
<applet code="StaticRects.class" height=160 width=300></applet>
The code is as follows:
package helloworld;
import java.awt.*;
/**
*
* @author RikudoSennin
*/
public class StaticRects extends AnimationBase {
public void drawFrame(Graphics g) {
// Draw set of nested black rectangles on a red background.
// Each nested rectangle is separated by 15 pixels on all sides
// from the rectangle that encloses it. The applet is
// assumed to be 300 pixels wide and 160 pixels high.
int inset; // Gap between borders of applet and one of the rectangles.
int rectWidth, rectHeight; // The size of one of the rectangles.
g.setColor(Color.red);
g.fillRect(0, 0, 300, 160); // Fill the entire applet with red.
g.setColor(Color.black); // Draw the rectangles in black.
inset = 0;
rectWidth = 299; // Set size of the first rect to size of applet
rectHeight = 159;
while (rectWidth >= 0 && rectHeight >= 0) {
g.drawRect(inset, inset, rectWidth, rectHeight);
inset += 15; // rects are 15 pixels apart
rectWidth -= 30; // width decreases by 15 pixels on left and 15 on right
rectHeight -= 30; // height decreases by 15 pixels on top and 15 on bottom
}
} // end paint()
} // end class StaticRects
(This is the copied version)
Now, I get the following error:
java.lang.NoClassDefFoundError: StaticRects (wrong name: helloworld/StaticRects)
Note that AnimationBase is a class defined elsewhere in the project which extends JApplet, and its class is included in the same directory.
What am I doing wrong? (it's probably some nooby error, but then again, I am a noob in Java).
Will appreciate any and all answers, thanks in advance :)
EDIT: Oh yeah, I'm using JDK 1.7.0 with NetBeans 7.0.1.