【发布时间】:2012-05-23 04:41:56
【问题描述】:
我正在尝试将我的 LWJGL 应用程序移植到 Applet 以在线播放,但是,我不知道如何为本地人提供正确的路径。
这是 .java 小程序代码:
package net.foxycorndog.idk.applet;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import net.foxycorndog.idk.Idk;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
public class IdkApplet extends Applet
{
Canvas drawCanvas;
Idk idk;
/** is the game loop running */
boolean running = false;
public void startLWJGL()
{
idk.start(drawCanvas);
}
/**
* Tell game loop to stop running, after which the LWJGL Display will be
* destroyed. The main thread will wait for the Display.destroy().
*/
private void stopLWJGL()
{
running = false;
try
{
idk.getGameThread().join();
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
public void start()
{
}
public void stop()
{
}
/**
* Applet Destroy method will remove the canvas, before canvas is destroyed
* it will notify stopLWJGL() to stop the main game loop and to destroy the
* Display
*/
public void destroy()
{
super.destroy();
System.exit(0);
}
public void init()
{
Idk.init();
idk = new Idk();
setLayout(new BorderLayout());
try
{
drawCanvas = new Canvas()
{
public final void addNotify()
{
super.addNotify();
startLWJGL();
}
public final void removeNotify()
{
stopLWJGL();
super.removeNotify();
}
};
setSize(640, 512);
drawCanvas.setSize(getWidth(), getHeight());
add(drawCanvas);
drawCanvas.setFocusable(true);
drawCanvas.requestFocus();
drawCanvas.setIgnoreRepaint(true);
setVisible(true);
}
catch (Exception e)
{
System.err.println(e);
throw new RuntimeException("Unable to create display");
}
}
protected void initGL()
{
}
}
HTML 代码如下:
<html>
<body>
<center>
<div class="rounded">
<applet code="net.foxycorndog.idk.applet.IdkApplet" name="theapplet" archive="Idk.jar" width="640" height="512" codebase="../applets/Idk">
<!-- The following tags are mandatory -->
<!-- Name of Applet, will be used as name of directory it is saved in, and will uniquely identify it in cache -->
<param name="al_title" value="appletloadertest">
<!-- Main Applet Class -->
<param name="al_main" value="net.foxycorndog.idk.applet.IdkApplet">
<!-- List of Jars to add to classpath -->
<param name="al_jars" value="lwjgl_applet.jar.pack.lzma, lwjgl.jar.pack.lzma, lwjgl_util.jar.pack.lzma">
<!-- signed windows natives jar in a jar -->
<param name="al_windows" value="windows_natives.jar.lzma">
<!-- signed linux natives jar in a jar -->
<param name="al_linux" value="linux_natives.jar.lzma">
<!-- signed mac osx natives jar in a jar -->
<param name="al_mac" value="macosx_natives.jar.lzma">
<!-- signed solaris natives jar in a jar -->
<param name="al_solaris" value="solaris_natives.jar.lzma">
<!-- Tags under here are optional -->
<!-- whether to use cache - defaults to true -->
<!-- <param name="al_cache" value="true"> -->
<!-- Version of Applet (case insensitive String), applet files not redownloaded if same version already in cache -->
<!-- <param name="al_version" value="0.1"> -->
<!-- Specify the minimum JRE version required by your applet, defaults to "1.5" -->
<!-- <param name="al_min_jre" value="1.6"> -->
<!-- background color to paint with, defaults to white -->
<!-- <param name="boxbgcolor" value="#000000"> -->
<!-- foreground color to paint with, defaults to black -->
<!-- <param name="boxfgcolor" value="#ffffff"> -->
<!-- logo to paint while loading, will be centered, defaults to "appletlogo.gif" -->
<!-- <param name="al_logo" value="appletlogo.gif"> -->
<!-- progressbar to paint while loading. Will be painted on top of logo, width clipped to percentage done, defaults to "appletprogress.gif" -->
<!-- <param name="al_progressbar" value="appletprogress.gif"> -->
<!-- whether to run in debug mode -->
<!-- <param name="al_debug" value="true"> -->
<!-- whether to prepend host to cache path - defaults to true -->
<!-- <param name="al_prepend_host" value="true"> -->
<param name="separate_jvm" value="true">
<p>
You're browser must have java enabled to view this content. If you do not have jave installed or the newest version, you can click here to update it to the latest version.
<a href="http://java.com/en/download/">Java</a>
</p>
</applet>
</div>
</center>
</body>
</html>
这是错误输出:
Exception in thread "Thread-14" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:132)
at net.foxycorndog.presto2d.PrestoGL2D.createFrame(PrestoGL2D.java:172)
at net.foxycorndog.idk.Frame.init(Frame.java:163)
at net.foxycorndog.idk.Frame.<init>(Frame.java:75)
at net.foxycorndog.idk.Idk$1$1.<init>(Idk.java:118)
at net.foxycorndog.idk.Idk$1.run(Idk.java:118)
【问题讨论】:
-
你在使用LWJGL AppletLoader吗?
-
不,我不是。现在我是并且它正在工作,有点。我无法检索我的资源。 “java.lang.RuntimeException:找不到资源:org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:69) 上的 res/images/font/pixel.ttf ...”有什么想法吗?
-
我在下面的答案中发表了评论,请随时接受,因为它似乎已经解决了您的(初始)问题。对于资源加载问题,请发布一个单独的问题,并在其中包含您的资源加载代码和存储它们的项目结构。
标签: java applet lwjgl unsatisfiedlinkerror