在网站上运行Java applet [英] Running a Java applet on a website

查看:202
本文介绍了在网站上运行Java applet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Eclipse创建了一个Java游戏。它有11个类(有一个主要类别,其他一切)。我以下列方式将其称为小程序:

 <! - 这是加载Handler类的小程序处理程序运行游戏 - > 
< td colspan =3>< applet code =Handler.classcodebase =历史冒险阿拉莫冒险/name =阿拉莫战斗冒险width =680height =509 archive =Handler.jarid =Alamo战斗冒险>
< / applet>< / td>

随着它上传到网站,它显示一个错误,并告诉我点击详细信息。当我选择它,它告诉我ClassNotFoundException:Handler.class



代码是在身体,我没有任何东西在头上。我做错了什么?



这是我的页面的其余代码。实际的测试页可以在www.kluckhohndesign.com找到

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>

< script language =javascripttype =text / javascript>
<! -
函数popitup(url){
newwindow = window.open(url,'name','height = 510,width = 500');
if(window.focus){newwindow.focus()}
return false;
}

// - >
< / script>

< title>阿拉莫战斗冒险< / title>
< / head>

< body>
< blockquote>& nbsp;< / blockquote>
< table width =1300border =0align =centercellpadding =0cellspacing =0>
< tr>
< td width =318height =160>& nbsp;< / td>
< td colspan =3>< img src =Alamo Battle Adventure.jpgwidth =680height =160alt =Top Banner/>< / td>
< td width =318& nbsp;< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td width =226>< a href =howtoplay.htmlonclick =return popitup('howtoplay.html')>< img src =如何播放width =226height =52alt =如何播放/>< / a>< / td>
< td width =226>& nbsp;< / td>
< td width =227>< a href =Help.htmlonclick =return popitup('help.html')>< img src =help.jpgwidth =226height =52alt =帮助/>< / a>< / td>
< td>& nbsp;< / td>
< tr>
< td>< img src =Alamo Pencil.jpgwidth =318height =250alt =Alamo Drawing/>< / td>
<! - 这是加载处理程序类以运行游戏的小程序处理程序 - >
< td colspan =3>< applet code =Handler.jarcodebase =历史冒险Alamo冒险/name =Alamo战斗冒险width =680height =509 archive =Handler.jarid =Alamo战斗冒险/>
< / applet>< / td>
< td>< img src =texans.jpgwidth =318height =250alt =德州人绘图/>< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td colspan =3>& nbsp;< / td>
< td>& nbsp;< / td>
< / tr>
< tr>
< td>& nbsp;< / td>
< td colspan =3>& nbsp;< / td>
< td>& nbsp;< / td>
< / tr>
< / table>
< / body>
< / html>


解决方案

这应该让你进一步:

 < html> 
< body>
< applet
code =Handler
codebase =http://www.kluckhohndesign.com/History%20Adventure%20Alamo%20Adventure/
name =Alamo战斗冒险
width =680
height =509
archive =Handler.jar
id =Alamo战斗冒险>
< / applet>
< / body>
< / html>

您可以省略 http://www.kluckhohndesign.com/ 前缀在代码库。



现在它导致一个 InvocationTargetException






  1. 代码属性应该是类的完整限定名称&与罐无关。大多数人认为FQN等于 Handler.class ,但实际上意味着只是 Handler

  2. 代码库可以简单地历史%20Adventure%20Alamo%20Adventure / 如果您的网站脱落。由于空格在网址中无效,因此需要%20 。再次,大多数部署者根本不会使用目录名空间,因为这个原因。

  3. applet 元素从来不是要像你原来的页面所示的那样自我关闭。相反,它需要一个明确的< / applet> 关闭元素。

  4. 请保持测试在我建议的更简单的页面,没有所有其他cruft。


I have created a Java game using Eclipse. It has 11 classes (with one main class that calls everything else). I called it as an applet in the following manner:

<!-- This is the applet handler to load the Handler Class to run the game -->
<td colspan="3"><applet code="Handler.class" codebase="History Adventure Alamo Adventure/" name="Alamo Battle Adventure" width="680" height="509" archive="Handler.jar" id="Alamo Battle Adventure">
</applet></td>

With it uploaded to the website, it shows an error and tells me to click for details. When I select it, it tells me ClassNotFoundException: Handler.class

The code is in the body and I have nothing in the head. What have I done wrong?

Here is the rest of my code for the page. The actual test page can be found at www.kluckhohndesign.com

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
    newwindow=window.open(url,'name','height=510,width=500');
    if (window.focus) {newwindow.focus()}
    return false;
}

// -->
</script>

<title>Alamo Battle Adventure</title>
</head>

<body>
<blockquote>&nbsp;</blockquote>
<table width="1300" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="318" height="160">&nbsp;</td>
    <td colspan="3"><img src="Alamo Battle Adventure.jpg" width="680" height="160" alt="Top Banner" /></td>
    <td width="318">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td width="226"><a href="howtoplay.html" onclick="return popitup('howtoplay.html')"><img src="How to Play.jpg" width="226" height="52" alt="How to Play" /></a></td>
    <td width="226">&nbsp;</td>
    <td width="227"><a href="Help.html" onclick="return popitup('help.html')"><img src="help.jpg" width="226" height="52" alt="Help" /></a></td>
    <td>&nbsp;</td>
  <tr>
    <td><img src="Alamo Pencil.jpg" width="318" height="250" alt="Alamo Drawing" /></td>
<!-- This is the applet handler to load the Handler Class to run the game -->
    <td colspan="3"><applet code="Handler.jar" codebase="History Adventure Alamo Adventure/" name="Alamo Battle Adventure" width="680" height="509" archive="Handler.jar" id="Alamo Battle Adventure" />
    </applet></td>
    <td><img src="texans.jpg" width="318" height="250" alt="Texans Drawing" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td colspan="3">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>

解决方案

This should get you further:

<html>
<body>
<applet
    code="Handler"
    codebase="http://www.kluckhohndesign.com/History%20Adventure%20Alamo%20Adventure/"
    name="Alamo Battle Adventure"
    width="680"
    height="509"
    archive="Handler.jar"
    id="Alamo Battle Adventure" >
</applet>
</body>
</html>

You can leave out the http://www.kluckhohndesign.com/ prefix on the codebase.

Now it causes an InvocationTargetException. But ask a new question about that.

Further notes

  1. The code attribute should be the fully qualified name of the class & has nothing to do with the Jar. Most people think FQN equates to Handler.class but it actually means just Handler.
  2. The codebase can be simply History%20Adventure%20Alamo%20Adventure/ if it is coming off your site. It needs the %20 for spaces, as spaces are not valid in an URL. Then again, most deployers would not use directory names with spaces at all, for that very reason.
  3. The applet element was never meant to be 'self closed' as was shown in your original page. Instead it needs an explicit </applet> closing element.
  4. Please keep testing in the simpler page I suggested, without all that other cruft.

这篇关于在网站上运行Java applet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆