Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6469381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:01+00:00 2026-05-25T05:59:01+00:00

I am just starting to learn Java (woohoo!!) and I’m reading a book called

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:59:02+00:00Added an answer on May 25, 2026 at 5:59 am

    The package name must be present in three places:

    • in the Java source file

      package helloworld;

    • in the applet tag:

      <applet code="helloworld.StaticRects" height=160 width=300></applet>

    • as a subdirectory of your codebase directory, which by default is the directory containing your HTML file:

      blah/mypage.html

      blah/helloworld/StaticRects.class

    If you can get a different applet to work in a named package, then the problem must be with the code. Your StaticRects class works fine for me if I use the following minimal AnimationBase class:

    package helloworld;
    
    import java.awt.Graphics;
    import javax.swing.JApplet;
    
    public abstract class AnimationBase extends JApplet {
        public void paint(Graphics g) {
            this.drawFrame(g);
        }
    
        public abstract void drawFrame(Graphics g);
    }
    

    My directory hierarchy looks like this:

    html/:
    applet.html helloworld

    html/helloworld:
    AnimationBase.class StaticRects.class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A friend is just starting to learn Java, using IntelliJ. He asks how can
I'm just starting to learn to use HashMap and reading the java tutorial, but
Hi I'm just starting to learn Python, I'm using the book learn python the
Just starting to learn ASP.NET (C#) and I am using Visual Studio 2008. I
I am just starting to learn F#. In several F# coding examples I see
I'm just starting to learn how network programming in C works, and I've written
I'm just starting to learn JSP (and I'm pretty new to Java in general),
I'm just starting to learn F# using VS2010 and below is my first attempt
I'm just starting to learn Java's RMI, and believe I understand the process, client
I'm a flash developer with no previous Java experience, just starting to learn android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.