如何在 HTML 中嵌入 jar [英] How to embed jar in HTML
问题描述
已经有很多关于此的资源,但我似乎无法让它发挥作用.我究竟做错了什么?jar 文件位于:
There are a lot of resources on this already but I just can't seem to get it to work. What am I doing wrong? The jar file is at:
http://www.alexandertechniqueatlantic.ca/multimedia/AT-web-presentation-imp.jar
我用来嵌入的代码是:
<APPLET ARCHIVE="multimedia/AT-web-presentation-imp.jar"
CODE="ImpViewer.class"
WIDTH=100%
HEIGHT=100%>
</APPLET>
我正在使用的测试页面位于:
The test page I am using is at:
http://www.alexandertechniqueatlantic.ca/test.php
当我下载 jar 时它运行良好,所以我确定问题仅在于 html 嵌入.请帮忙!
When I download the jar it runs fine, so I am certain the problem is only with the html embedding. Pleas help!
此外,我收到以下错误:
Also, I get the following error:
java.lang.ClassCastException: ImpViewer 不能转换为java.applet.Applet
java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet
推荐答案
java.lang.ClassCastException: ImpViewer cannot be cast to java.applet.Applet
小程序"不是小程序.
顺便说一句 - 漂亮的用户界面.就像红色飞溅淡入欢迎介绍研讨会"页面的方式一样.很流畅.
BTW - nice UI. Like the way the red splash fades in to the 'Welcome Introductory Workshop' page. Very smooth.
使用 Java Web Start 从链接启动它(& 请不要尝试填鸭式如此漂亮的 UI 变成了网页).
Launch it from a link using Java Web Start (& please don't try and cram such a beautiful UI into a web page).
如果客户坚持要将 GUI 塞进网站,那么(为我打耳光 &)试试这个 hack.
If the client insists on the GUI being crammed into a web site then (slap them for me &) try this hack.
/*
<APPLET
ARCHIVE="AT-web-presentation-imp.jar"
CODE="ImpViewerApplet"
WIDTH=720
HEIGHT=564>
</APPLET>
*/
import java.awt.*;
import java.applet.*;
import java.util.*;
public class ImpViewerApplet extends Applet {
public void init() {
setLayout(new BorderLayout());
Window[] all = Window.getWindows();
ArrayList<Window> allList = new ArrayList<Window>();
for (Window window : all) {
allList.add(window);
}
String[] args = {};
ImpViewer iv = new ImpViewer();
iv.main(args);
all = Window.getWindows();
for (Window window : all) {
if (!allList.contains(window) && window.isVisible()) {
if (window instanceof Frame) {
Frame f = (Frame)window;
Component[] allComp = f.getComponents();
Component c = f.getComponents()[0];
f.remove(c);
f.setVisible(false);
add(c);
validate();
}
}
}
}
}
重点是hack"这个词.
The emphasis is on the word 'hack'.
Frame
会在消失前闪烁到屏幕上.- 它只能在 720x564 像素下工作,不像
java.awt.Frame
可以调整为任何大小.但是,无论如何,你的100%"宽度/高度有点乐观.有些浏览器会遵守这些限制,有些则不会.
- The
Frame
will flash onto screen before disappearing. - It will only work at 720x564 px, unlike the
java.awt.Frame
which was resizable to any size. But then, your '100%' width/height was being a bit optimistic anyway. Some browsers will honour those constraints, others will not.
这篇关于如何在 HTML 中嵌入 jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!