【发布时间】:2018-02-16 13:12:35
【问题描述】:
我正在创建一个简单的小程序。当我通过终端appletviewer helloworld.html 运行应用程序时,我遵循“Java in 24h”中的教程。有效。我看到“点击我”按钮和“Hello World”,但是当我通过浏览器(Safari、Chrome、Firefox)打开 helloworld.html 时。我没有看到小程序。它只是有“结束线!”
我为我的浏览器启用了 java pluins,我正在使用 macosx
我的代码:
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
//<applet code = Saluton width = 300 height = 300> </applet>
public class Saluton extends Applet {
public void init() {
Button buttons = new Button("Click me!");
this.add(buttons);
}
public void paint(Graphics screen)
{
Graphics2D screen2D = (Graphics2D) screen;
screen2D.drawString("Hello World",120,120);
}
}
和 HTML 文件
<head>
<title>Hello World!</title>
</head>
<body bgcolor = green text = "#FF00FF">
<center>
<applet
code = Saluton
width = 300
height = 150
>
<p>end line!</p>
</applet>
</center>
</body>
</html>
【问题讨论】:
-
这是java还是javascript?
-
Java 小程序已过时,浏览器已停止支持,现在正在阻止它们。而是从 AWT 迁移到 Swing,并至少使用
JApplet到JFrame。 -
是的,现在没有理由使用小程序,它们被归类为有风险、危险和过时的,为什么要运行小程序?现在有更好的解决方案!
-
@TeoMihaila 我添加了一个答案,因为评论太多了