Sign in to follow this  
yves032784

[java] need help, it's been a long time since i've used java

Recommended Posts

yves032784    160
It's been a while since i've coded anything in Java, so I need your help. I got this tutorial on applets at http://java.sun.com/docs/books/tutorial/applet/overview/index.html
import java.applet.Applet;
import java.awt.Graphics;

public class yves extends Applet {

    StringBuffer buffer;

    public void init() {
	buffer = new StringBuffer();
        addItem("initializing... ");
    }

    public void start() {
        addItem("starting... ");
    }

    public void stop() {
        addItem("stopping... ");
    }

    public void destroy() {
        addItem("preparing for unloading...");
    }

    void addItem(String newWord) {
        System.out.println(newWord);
        buffer.append(newWord);
        repaint();
    }

    public void paint(Graphics g) {
	//Draw a Rectangle around the applet's display area.
        g.drawRect(0, 0, size().width - 1, size().height - 1);

	//Draw the current string inside the rectangle.
        g.drawString(buffer.toString(), 5, 15);
    }
}
Tried that exact peice of code and got this error:
Exception in thread "main" java.lang.NoClassDefFoundError: yves
Press any key to continue...
I'm using the latest version of the SDK

Share this post


Link to post
Share on other sites
daireq    236
Quote:
Original post by yves032784
It's been a while since i've coded anything in Java, so I need your help.

I got this tutorial on applets at http://java.sun.com/docs/books/tutorial/applet/overview/index.html
*** Source Snippet Removed ***
Tried that exact peice of code and got this error:

Exception in thread "main" java.lang.NoClassDefFoundError: yves
Press any key to continue...


I'm using the latest version of the SDK


Looks like you're trying to write an application (run from the command line) instead of an applet (which has to be embedded in a web page)

take a look at this trail first:
http://java.sun.com/docs/books/tutorial/getStarted/application/index.html

then to write GUI applications, the 'ole swing trail is the place to go:
http://java.sun.com/docs/books/tutorial/uiswing/index.html

D.

Share this post


Link to post
Share on other sites
H_o_p_s    877
Quote:
Original post by daireq
Looks like you're trying to write an application (run from the command line) instead of an applet (which has to be embedded in a web page)

Applets don't need to be in a webpage, I use applets all the time for simple sound managers...

Share this post


Link to post
Share on other sites
jsgcdude    250
However, to run the class above the op (original poster) would have to either put it in a webpage or use appletviewer (as this is a newbie question I doubt if its an applet in an application...).

The error says to me either 1) the op isn't specifying the path correctly or 2) if it IS in a webpage then he may not have a 1.4+ version of the jre setup as the plugin.

Need more info op, how are you running the applet?

Share this post


Link to post
Share on other sites
Raghar    96
Where is located the wrongly named yves.class? You should use capital leters for class names.

Try to write application first, browsers are BAD company.
Of course if you have set classpath to some value, you should have "-cp .", or is it "-cp.", in the command line.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this