How to preview a Swing Applet?

Discussion in 'Mac Programming' started by briantology, Feb 26, 2008.

  1. macrumors 6502

    Jun 5, 2006
    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?
  2. macrumors newbie

    Sep 1, 2006
    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
  3. macrumors 6502a

    Dec 4, 2006
    Katy, Texas
    What exactly happens in Terminal when you enter "appletviewer" ?

    Post your hello world example here and I'll try it.
  4. thread starter macrumors 6502

    Jun 5, 2006
    Well, when I try: appletviewer
    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
  5. macrumors newbie

    Sep 8, 2007
    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.
  6. thread starter macrumors 6502

    Jun 5, 2006
    Wow, that was it. Nice and easy. Thanks bloomberg!

Share This Page