View Full Version : How to preview a Swing Applet?

Feb 26, 2008, 10:40 AM
I'm working on this Applet written in Swing, and for some reason I can't preview it using AppletLauncher, appletviewer, Safair or Mozilla. However, when I put it on a PC and open it in IE or Mozilla, it works. I've even tried testing a very basic swing applet that just says "Hello World", and it still doesn't work. I just get a box as the correct dimensions but with an X in the top left corner.
I'm running 10.5.2 and have Java 1.5.0_13. Any ideas on how I can view these Swing applets on OS X?

Feb 26, 2008, 02:10 PM
Applets are so 20th century. You should look at Java Web Start, or JSF+javascript to do what you are doing, if possible. Sorry I don't have the answer to your actual question

Feb 26, 2008, 04:48 PM
What exactly happens in Terminal when you enter "appletviewer appletname.java" ?

Post your hello world example here and I'll try it.

Feb 26, 2008, 11:05 PM
Well, when I try: appletviewer simple.java
it sits there for a second, then just returns a new line.
But when I try: appletviewer simple.html
a window pops up, but at the bottom of the window it says "Start: applet not initialized."

Here is the simple applet code:
import javax.swing.*;
import java.awt.*;

public class simple extends JApplet {

public void init() {
JLabel label = new JLabel("Testing a Swing Applet");
setLayout(new FlowLayout());

And this is the HTML file I've been testing with:
<title>Simple Applet in Swing</title>
<applet code="simple.class" width=200 height=50></applet>

Here's an error that pops up in the Java Console when I try to view the applet in a web browser:
java.lang.UnsupportedClassVersionError: Bad version number in .class file

Feb 26, 2008, 11:23 PM
java.lang.UnsupportedClassVersionError: Bad version number in .class file

This is thrown when class files are compiled with a different version of java (usually newer) than the one being used to run them. Did you update your jdk recently or move class files between computers? Try recompiling all your sources with your current jdk and try again.

Feb 26, 2008, 11:49 PM
Wow, that was it. Nice and easy. Thanks bloomberg!