我正在尝试将我的 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)