[英]Java applet not loading on Mac, Safari or Chrome
Im just getting started with Java applets. 我刚刚开始使用Java小程序。 And while I have been creating them and running them in Eclipse just fine, when I go to open the HTML page in Safari or Chrome on a Mac, the applet will not load.
而且,尽管我一直在创建它们并在Eclipse中运行它们,但是当我在Safari或Mac上的Chrome中打开HTML页面时,将无法加载该applet。 Im running java 8, the latest update.
我正在运行Java 8,最新更新。
Am I missing something here? 我在这里想念什么吗? Here is the java and html file that I came using.
这是我使用的java和html文件。
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.Color;
import java.awt.*;
public class JavaTest extends Applet
{
public void paint( Graphics screen )
{
Font f = new Font( "TimesRoman", Font.ITALIC, 36 );
screen.setFont( f );
Color c = new Color( 40, 80, 120 );
screen.setColor( c );
screen.drawString( "Java Rocks!!", 100, 60 );
}
}
Here is the HTML file, in same file as java file, with file name index.html. 这是HTML文件,与Java文件位于同一文件中,文件名为index.html。
<HTML>
<APPLET width=300 height=300 code="JavaTest.class">
</APPLET>
</HTML>
The <applet>
tag is obsolete in HTML5 . <applet>
标记在HTML5中已过时。 Try replacing it with the <embed>
tag. 尝试用
<embed>
标记替换它。 Try this: 尝试这个:
<embed id="my-applet"
type="application/x-java-applet;version=1.6"
width="300"
height="300"
archive="my-applet.jar"
code="my.package.myclass"
pluginspage="http://java.com/download/"
myParam="my parameters" />
Notice that you have to modify the archive
and code
attributes to match that in your project. 注意,您必须修改
archive
和code
属性以匹配项目中的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.