[英]Running a Java applet on a website
我已經使用Eclipse創建了Java游戲。 它有11個類(其中一個主類調用其他所有類)。 我通過以下方式將其稱為小程序:
<!-- 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>
將其上傳到網站后,顯示錯誤,並告訴我單擊以獲取詳細信息。 當我選擇它時,它告訴我ClassNotFoundException:Handler.class
代碼在正文中,我頭上什么也沒有。 我做錯了什么?
這是該頁面的其余代碼。 實際的測試頁面可以在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> </blockquote>
<table width="1300" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="318" height="160"> </td>
<td colspan="3"><img src="Alamo Battle Adventure.jpg" width="680" height="160" alt="Top Banner" /></td>
<td width="318"> </td>
</tr>
<tr>
<td> </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"> </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> </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> </td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="3"> </td>
<td> </td>
</tr>
</table>
</body>
</html>
這應該使您更進一步:
<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>
您可以在代碼庫上省略http://www.kluckhohndesign.com/
前綴。
現在,它導致一個InvocationTargetException
。 但是,請問一個新的問題。
code
屬性應該是該類的完全限定名稱,並且與Jar無關。 大多數人認為FQN等於Handler.class
但實際上意味着Handler
。 History%20Adventure%20Alamo%20Adventure/
。 由於空格在URL中無效,因此需要%20
的空格。 同樣,出於這個原因,大多數部署人員根本不會使用帶有空格的目錄名稱。 applet
元素絕不會“自我關閉”。 相反,它需要一個顯式的</applet>
關閉元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.