简体   繁体   English

Java Applet不会运行

[英]Java applet wont run

I am trying to get a Java applet to run properly when linked to an HTML page in Dreamweaver CC. 我试图使Java小程序在Dreamweaver CC中链接到HTML页面时能够正常运行。 I'm new to all this so please bear with me here. 我是这一切的新手,所以请在这里忍受。 First I saved this code to a .java file 首先,我将此代码保存到一个.java文件中

//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 然后我将其编译为javac Triangle.java

After that, I inserted it into a Dreamwever page using: 之后,我使用以下命令将其插入到Dreamwever页面中:

<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: 现在,当我尝试在Chrome中打开页面时,出现读取错误:

UnsupportedClassVersionError Triangle: Unsupported major.minor version 52.0

This, as I have read, is an issue with using two incompatible Java versions? 如我所读,这是使用两个不兼容的Java版本的问题吗? In my Java Control Panel it says I am using version 1.8.0_20 and my JDK is jdk1.8.0_20. 在我的Java控制面板中,它说我正在使用1.8.0_20版本,而我的JDK是jdk1.8.0_20。

Does anyone see anything super obvious that I am doing wrong here? 有人看到我在这里做错什么超级明显吗?

  • Java 5 = 49 Java 5 = 49
  • Java 6 = 50 Java 6 = 50
  • Java 7 = 51 Java 7 = 51
  • Java 8 = 52 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)). 您使用Java 8编译了applet,但是在系统上安装了其他版本(然后,(chrome)网络浏览器使用了该版本)。 Try to uninstall all older java versions from your system and install the latest java version 8. 尝试从系统中卸载所有较旧的Java版本,然后安装最新的Java版本8。

You may check your java version by opening a command prompt (or a shell) and type: java -version 您可以通过打开命令提示符(或外壳程序)并输入以下命令来检查Java版本: 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. 进一步说明:如果您使用版本8编译小程序,由于尚未发布给公众,大多数人尚未安装它(请检查http ://java.com-JRE仍为Java 7)-大多数人们无法运行它。 I would therefore compile it for version 7. 因此,我将其编译为版本7。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM