Click to See Complete Forum and Search --> : Java appletviewer...


jetblackz
01-20-2003, 04:17 PM
appletviewer MyFirstApplet.html
*nothing returned nothing shown*
--

appletviewer -debug MyFirstApplet.html
> run
run sun.applet.Main MyFirstApplet.html
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
>
VM Started:
The application exited
--

MyFirstApplet.html

<html>
<head>
<title>MyFirstApplet</title>
</head>
<body>
<hr>
<applet code="MyFirstApplet.class" width=300 height=200>
<hr>
</body>
</html>

--

MyFirstApplet.class

import javax.swing.JApplet;
import java.awt.Graphics;

public class MyFirstApplet extends JApplet {

public void paint(Graphics g) {
g.drawString("To climb a ladder, start at the bottom rung", 20, 90);
}
}

--

Source: Java 2, Wrox
Tools: vi & Sun's Java SDK 1.4.1

Q: how do you normally test an applet? Any errors in my code & html?

Mozilla 1.2.1 & the same SDK doesn't run it either. A red cross on the top-left.

Arjay
01-21-2003, 09:48 PM
I'n new to java but it looks like your first two lines are wrong, well for what you want to do. I've edited your code to what i think it should be. I can't test it tho cos i'm on a new machine and haven't got nothing installed yet.

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

public class MyFirstApplet extends Applet {
public void paint(Graphics g) {
g.drawString("To climb a ladder, start at the bottom rung", 20, 90);
}
}


Also try here...

http://java.sun.com/docs/books/tutorial/

Good Luck!!

Hangdog42
01-21-2003, 10:00 PM
Uh, no. The original Java is fine. javax.swing.Japplet is simply an extension of Applet that can use the Swing components. And believe me, you want to be able to use Swing. And while using import java.awt.* is fine, so is import java.awt.Graphics. Since the code doesn't use anything out of awt other than Graphics, you don't need to use the more global import statment.

I think that this problem is actually appletviewer. If you go look at the Sun Developer site (http://developer.java.sun.com) you'll find that LOTS of people have problems with appletviewer.

Unfortunately, if you can't view it in Mozilla, I don't what else you could do. I write all my Java as applications, not applets so I don't have any good alternatives. Maybe try Opera? Or head over to the Sun site and see if someone posted a fix for applet viewer.

jetblackz
01-22-2003, 01:00 AM
There was a missing closing tag of applet in the html. Fixed. appletviewer popped up. At the status bar, it read , "applet not initialized." No error/exceptions in console where I executed the command.

BTW, the code is from the book. You can check it out at your local bookstore. Java 2 SDK 1.4 by Wrox. Page 17.