如何将小程序加入到WEB页中

shadowne 2010-01-19 12:52:35
这段是小程序,显示时间的
import java.awt.*;
import java.util.*;

public class Watch extends javax.swing.JApplet
{
private Color butterscotch = new Color(255, 204, 102);
private String lastTime = "";

public void init()
{
setBackground(Color.black);
}

public void paint(Graphics screen)
{
Graphics2D screen2D = (Graphics2D)screen;
Font type = new Font("Monospaced", Font.BOLD, 20);
screen2D.setFont(type);
GregorianCalendar day = new GregorianCalendar();
String time = day.getTime().toString();
screen2D.setColor(Color.black);
screen2D.drawString(lastTime, 5, 25);
screen2D.setColor(butterscotch);
screen2D.drawString(time, 5, 25);
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
//do nothing
}
lastTime = time;
repaint();
}
}
已编译生成Watch.class

这段是html源码
<html>
<head>
<title>Watch Applet</tilte>
</head>
<body>
<applet code="Watch.class" height="50" width="345">
This program requires a Java-enabled browser.
</applet>
</body>
</html>

为什么我打开html却没有任何东西
是不是漏了什么
...全文
91 4 打赏 收藏 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luffyke 2010-01-19
  • 打赏
  • 举报
回复
在"APPLET"标签中指定的宽度和高度一定要比小应用程序的绘图或打印的位置大,否则你在屏幕上就不会看到它了。
luffyke 2010-01-19
  • 打赏
  • 举报
回复
applet实在是很麻烦.路径很关键.看看是不是没有把CLASS放当前目录.如果没有放,要把class加上相对路径,要不它可找不着.
luffyke 2010-01-19
  • 打赏
  • 举报
回复
用这个看看<jsp:plugin type="applet" code="Watch.class" height="50" width="345" >
shadowne 2010-01-19
  • 打赏
  • 举报
回复
我知道了,是我自己的html源码错了
<title>Watch Applet </tilte>

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧