0

I am trying to get a Java applet to run properly when linked to an HTML page in Dreamweaver CC. I'm new to all this so please bear with me here. First I saved this code to a .java file

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

public class Triangle extends Applet {

    public void paint (Graphics g){
        int bottomX=80;
        int bottomY=200;
        int base=100;
        int height=100;
        g.drawLine(bottomX,bottomY,bottomX+base,bottomY);
        g.drawLine(bottomX+base,bottomY,bottomX+base/2,bottomY-height);
        g.drawLine(bottomX+base/2,bottomY-height, bottomX,bottomY); 
    }
}

I then compiled it entering javac Triangle.java

After that, I inserted it into a Dreamwever page using:

<html>
    <applet code=Triangle.class width=400 height=400 > 
    </applet>
</html>

Now when I try and open the page in Chrome I get an error reading:

UnsupportedClassVersionError Triangle: Unsupported major.minor version 52.0

This, as I have read, is an issue with using two incompatible Java versions? In my Java Control Panel it says I am using version 1.8.0_20 and my JDK is jdk1.8.0_20.

Does anyone see anything super obvious that I am doing wrong here?

Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55
  • 2
    You've compiled it with one version of Java (probably Java 8), but are attempting to run it with an older version. You need to get Chrome to updated – MadProgrammer Aug 24 '14 at 04:03
  • 1) Why code an applet? If it is due to spec by your instructor, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why use AWT components rather than Swing? See [this answer](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon AWT. – Andrew Thompson Aug 24 '14 at 14:06

1 Answers1

0
  • Java 5 = 49
  • Java 6 = 50
  • Java 7 = 51
  • Java 8 = 52

You compiled your applet with Java 8 however have a different version installed on your system (which is then used by your (chrome) webbrowser(s)). Try to uninstall all older java versions from your system and install the latest java version 8.

You may check your java version by opening a command prompt (or a shell) and type: java -version

One further note: If you compile your applet with version 8, which most people did not yet install since it not has been released to the general public (check http://java.com - JRE is still java 7) - most of the people can not run it. I would therefore compile it for version 7.

Lonzak
  • 9,334
  • 5
  • 57
  • 88