【问题标题】:Embed applet into html page issue将小程序嵌入 html 页面问题
【发布时间】:2014-04-01 16:51:43
【问题描述】:

我无法嵌入一个简单的小程序。我认为类文件名的相对/绝对路径的设置是问题所在。我尝试了许多不同的方法来做到这一点,但没有一个奏效。只有一个例外。如果我将 indexApplet.html 文件放在 bin 文件夹中,那么它可以工作。但我想将 indexApplet.html 保留在它之外。对于此事,我将非常感谢任何帮助。

这是我的html代码和文件夹结构:

[code]
<!doctype html>
<html>
<head>
<meta charset="utf-8">

<title>Java Game</title>

</head>

<body>

<applet code="test/bin/first/hello.class"  width="800" height="600" alt="Java Game" title="Go and Play"></applet>

</body>
</html>
[/code]

类文件位于:C:\Users\Valentin\workspace\test\bin\first

我想将 indexApplet.html 文件放在测试文件夹之外。

【问题讨论】:

  • 那么您的indexApplet.html 已在文件夹C:\Users\Valentin\workspace 中,对吧?

标签: java html path applet


【解决方案1】:

假设您正在查看来自C:\Users\Valentin\workspace 的小程序,并且在first 包中声明了类hello,那么您需要添加codebase 属性:

<applet code="first.hello.class" width="800" height="600" codebase="test/bin">

阅读:Using applet, object and embed Tags

【讨论】:

  • hello 是否在 first 包中声明?
  • 你这是什么意思? “宣布”。文件 hello.class 位于标记为 first 的文件夹中。
  • 它是否以package first; 开头? - 如果不是太大,请发布您的hello.java
  • 先打包;导入 java.applet.Applet;导入 java.awt.Graphics;公共类 hello 扩展 Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } }
  • NoClassDefFoundError 你好(错误的名字:first/hello)
猜你喜欢
  • 1970-01-01
  • 2011-10-15
  • 2011-06-08
  • 1970-01-01
  • 2014-06-10
  • 2010-11-19
  • 2015-12-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多