- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试一些 Java/JavaScript 编码,但似乎遇到了困难。我试图将参数从 Java 传递到 JavaScript,但无论我做什么“JSObject jso = JSObject.getWindow(this);”总是抛出异常。我已经进行了一些搜索,但找不到任何解决方案。我从网站 ( http://www.codejava.net/java-se/applet/liveconnect-the-api-for-communication-between-java-applet-and-javascript ) 窃取了下面的代码,并且在 JavaScript 或 Java 中没有看到任何错误,并且两个文件都编译正确。
我已将plugin.jar 添加到buildpath 中,并确保jfxrt.jar 不在构建路径中。我认为 jre7 中的plugin.jar 可能有问题,所以我尝试了jre6,但得到了同样的错误。我正在使用的代码如下。
Java 代码:
package test;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import netscape.javascript.*;
public class TestApplet extends JApplet {
private JButton button = new JButton("Call Javascript");
private JLabel label = new JLabel();
public void init() {
getContentPane().setLayout(new BorderLayout());
getContentPane().add(button, BorderLayout.NORTH);
getContentPane().add(label, BorderLayout.SOUTH);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Thread runner = new Thread(new Runnable() {
public void run() {
try {
testLiveConnect();
} catch (JSException jse) {
// Error
jse.printStackTrace();
}
}
});
runner.start();
}
});
}
private void testLiveConnect() throws JSException {
JSObject jso = JSObject.getWindow(this);
// call Javascript's method foo() with no argument
String result = (String) jso.call("foo", null);
label.setText(result);
// delay 2 seconds to see the result
try { Thread.sleep(2000); } catch (InterruptedException ie) {};
// call Javascript's method foo() with two arguments
result = (String) jso.call("bar", new String[] {"Alice", "Alisa"});
label.setText(result);
try { Thread.sleep(2000); } catch (InterruptedException ie) {};
// execute a Javascript expression
String expression = "alert('Hi, I am from Javascript.');";
jso.eval(expression);
try { Thread.sleep(2000); } catch (InterruptedException ie) {};
// get value of a named member from Javascript
result = (String) jso.getMember("coop");
label.setText(result);
try { Thread.sleep(2000); } catch (InterruptedException ie) {};
// get value of an indexed member from Javascript
result = (String) jso.getSlot(1);
label.setText(result);
}
}
JavaScript 代码:
<html>
<head>
<title>LiveConnect - Java-Javascript communnication demo</title>
</head>
<body>
<center>
<applet id="testApplet"
code="TestApplet.class"
width="200" height="80"
>
</applet>
</center>
</body>
<script type="text/javascript">
var coop = "Ooops!";
this[1] = "Slot 1";
function foo() {
return "This is from foo()";
}
function bar(firstName, lastName) {
return "Greeting " + firstName + " " + lastName + "!";
}
</script>
</html>
抛出异常:
netscape.javascript.JSException
at netscape.javascript.JSObject.getWindow(Unknown Source)
at test.TestApplet.testLiveConnect(TestApplet.java:34)
at test.TestApplet.access$0(TestApplet.java:33)
at test.TestApplet$1$1.run(TestApplet.java:22)
at java.lang.Thread.run(Unknown Source)
最佳答案
这曾经让我发疯。 Java7 显然附带了 2 个 jar,其中包含同一类的不同实现。 jfxrt.jar和plugin.jar
我通过简单地从类路径中删除 jfxrt.jar 解决了这些问题。您必须深入研究如何为您的构建系统做到这一点。在Intellij中,您可以访问:
文件 -> 项目结构 -> SDK
然后,在类路径选项卡上,突出显示 jfxrt.jar 并单击“-”
预计到达时间:我找到了最初对我有帮助的答案,其中包含更多信息:https://stackoverflow.com/a/14156602/1057157
关于java - JSObject.getWindow(this);总是抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18038951/
它们有什么区别?据我所知,他们都做同样的事情。 最佳答案 如果你去资源,你会发现PhoneWindow.class实现了 Window.setBackgroundDrawable 方法: @Overr
编辑:在形成这个问题时,我没有注意到目标窗口是模态窗口,所以我尝试的方法是错误的。我应该一直使用 GetModal,而不是 GetWindow。留在这里作为 future 旅行者的潜在引用 我正在尝试
JSObject.equals 的文档说: Determines if two JSObject objects refer to the same instance. 相反,以下表达式的计算结果为
这可能是一个愚蠢的问题,但我有以下情况:我想在每次打开应用程序时设置窗口布局,例如更改状态栏颜色。所以我创建了我的应用程序文件,因为我听说如果您在应用程序文件中而不是在 MainActivity 中检
我已经为 ics 创建了一个锁屏,它将取代默认的锁屏。在我的代码中,我想使用 getWindow() 方法来设置 "android:hardwareAccelerated" true 以提高效率。 我
我正在尝试一些 Java/JavaScript 编码,但似乎遇到了困难。我试图将参数从 Java 传递到 JavaScript,但无论我做什么“JSObject jso = JSObject.getW
来自How to reference primaryStage我了解到,我可以使用 control.getScene.getWindow() 获取特定控件的 Stage,但这会返回一个 Window
我明白 TypeError: this.getWindow(...).$ is undefined 当我使用CKEDITOR.instances['pageContent'].getData();使用
下面一行代码中的getWindow()方法 this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_
在source for jQuery's offset() ,为什么不能直接用window呢? 最佳答案 以防元素实际上不在 window 上。例如,它可能位于 iFrame 或弹出窗口中。 关于ja
我看过以下帖子 How to keep background image size when software keyboard show Software keyboard resizes back
在我的 Android 项目中,我希望只有一个 fragment 的 softInputMode 为 adjustPan。 将以下行添加到我的 list (在 Activity 内)按预期工作: an
我正在尝试绘制一些颜色介绍对话框,我有几个按钮(用于选择颜色)和一个 CStatic 控制我将使用哪个窗口来绘制所选颜色它。但是,当我调用 m_myStatic.GetWindow( NULL ) 时
public class AircraftFragmentTab extends Fragment{ private String ac; public Aircr
我无法解决 getWindow();出于某种原因的方法... import java.applet.Applet; import netscape.javascript.JSObject; publi
我有一些Android应用程序的类文件,我有代码 protected void onCreate(Bundle bundle) { super.onCreate(bundle);
我正在尝试获取 Android 中的屏幕亮度。 场景是这样的:A 类调用 B 类的函数: A类: if(condition is true){ ClassB.function(); } B类: f
我按顺序调用了以下两个方法(按顺序使用适当的类级别字段) public const string ProcessName = "This is" public const string WindowT
我需要检查是否已在 ActionBarCompat 实例上设置叠加功能。 getWindow().hasFeature() 方法仅适用于 API 11 及更高版本。 如何检查 API = 11) {
我创建了一个完全适合设备显示的背景图像,没有状态栏和操作栏。这意味着我的设备的整个高度是 1280 像素。没有状态栏和操作栏它是 1038 像素。我的背景图片正好是 1038 像素高。当我将图像设置为
我是一名优秀的程序员,十分优秀!