Java Applet 不显示在 HTML 页面上

标签 java html

加载 HTML 页面时,我的 Java 小程序(称为 NameInLights.class)不显示。 .class 文件肯定存在,并且 HTML 的其他部分显示在页面上的正确位置。我的浏览器中启用了 Java,并且小程序在 AppletViewer 中运行良好。

这是我的java代码:

import java.util.Random;
import java.awt.*;
import java.applet.*;
public class NameInLights extends Applet {

    private static final long serialVersionUID = 1L;
    Random r = new Random();
    String name = "Imulsion";//must keep my real name secret! :)
    public void init(){
        setSize(500,500);
    }
    public void paint(Graphics g){
    g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));
    g.setFont(new Font("Comic sans ms",Font.BOLD,55));  
    g.drawString(name,125,250);
    for(int loop=0;loop<500;loop++)
    {
        int red = r.nextInt(255);
        int green = r.nextInt(255);
        int blue = r.nextInt(255);
        int x = r.nextInt(500);
        int y = r.nextInt(500);
        g.setColor(new Color(red,green,blue));
        g.setFont(new Font("Times New Roman",Font.BOLD,24));
        g.drawString("*",x,y);
    }
    }
}

这是我的 HTML:

<html>
 <body>
    <p>
     Here comes an awesome applet!
    </p>
    <br />
    <br />
    <applet code="NameInLights.class" width = 500 height = 500>
    </applet>
    <button type = "button" onclick = "window.location.reload()">
     Change applet colours
    </button>
 <body>
<html>

为什么不显示?

最佳答案

好的,Google Chrome 正式不支持已弃用的标签 applet。 使用标签 object 代替。

关于Java Applet 不显示在 HTML 页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11710694/

相关文章:

java - 当 textarea 与其他组件一起使用时,为什么 Java pack 无法正确调整框架大小?

html - :after pseudoelement 的 CSS3 过渡

html - Firefox 中的 Flexslider 关闭屏幕

java - 如何通过两个表中的公共(public)列获取数据

Java拆分正则表达式

javascript - 滚动上的粘性导航在 Safari 中表现得很奇怪

javascript - 如何删除没有值(value)的选项选择?

javascript - 点击元素跨容器遍历

java - 从 strings.xml 提供 layout_height 和 layout_width

java - 如何验证 java 对象从一种状态到另一种状态的转换[两种状态都是用户定义的]?