简体   繁体   English

在网站上运行Java小程序

[英]Running a Java applet on a website

I have created a Java game using Eclipse. 我已经使用Eclipse创建了Java游戏。 It has 11 classes (with one main class that calls everything else). 它有11个类(其中一个主类调用其他所有类)。 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 当我选择它时,它告诉我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 实际的测试页面可以在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. 您可以在代码库上省略http://www.kluckhohndesign.com/前缀。

Now it causes an InvocationTargetException . 现在,它导致一个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. code属性应该是该类的完全限定名称,并且与Jar无关。 Most people think FQN equates to Handler.class but it actually means just Handler . 大多数人认为FQN等于Handler.class但实际上意味着Handler
  2. The codebase can be simply History%20Adventure%20Alamo%20Adventure/ if it is coming off your site. 如果代码库不在您的站点上,则它可以只是History%20Adventure%20Alamo%20Adventure/ It needs the %20 for spaces, as spaces are not valid in an URL. 由于空格在URL中无效,因此需要%20的空格。 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. 如原始页面所示, applet元素绝不会“自我关闭”。 Instead it needs an explicit </applet> closing element. 相反,它需要一个显式的</applet>关闭元素。
  4. Please keep testing in the simpler page I suggested, without all that other cruft. 请继续在我建议的较简单的页面中进行测试,不要再进行其他操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM