现有的HTML元素如下所示:
https://developer.mozilla.org/de/docs/Web/API
可用的JAVA类如下所示:
https://xerces.apache.org/xerces2-j/javadocs/api/org/w3c/dom/Element.html
不幸的是,HTMLCanvasElement.包遗漏了一些更具体的元素--
我是,正在寻找一些更高级的Java ,它们至少支持HTMLCanvasElements (完整的WEP支持将是很好的)。
我到目前为止发现的是:
答:对于项目javafx-d3,我使用JavaFx WebView来控制一些JavaScript。Java与JavaScript之间的通信是基于netscape.javascript.JSObject的,在原则上工作得很好:
我可以把JSObject从JavaScript世界投到org.w3c.dom.Element .并使用其Java方法来操作DOM。
如果我想“深入一点”,例如控制一个HTMLCanvasElement,我必须基于JSObject编写自己的包装器。这是可能的,但感觉就像重新发明轮子。
B. Google 似乎提供了一些包装类。
com.google.gwt.dom.client.CanvasElement for HTMLCanvasElement
但是,我没有设法将com.google.gwt.core.client.JavaScriptObject)转换为GWT包装器类(从netscape.javascript.JSObject开始)。
如果这是可能的话,有人能举个例子吗?
有人知道如何运行下面的虚拟示例吗?
package main;
import elemental.client.Browser;
import elemental.html.AudioContext;
import elemental.html.AudioParam;
import elemental.html.Oscillator;
import elemental.html.Window;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class GwtElementDemo extends Application {
private Scene scene;
private Region browser;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
//set state title
stage.setTitle("JavaFx demo");
browser = new Region();
Window window = Browser.getWindow();
AudioContext audioContext = window.newAudioContext();
Oscillator osc = audioContext.createOscillator();
osc.setType(Oscillator.SQUARE);
osc.connect((AudioParam) audioContext.getDestination(), 0);
osc.getFrequency().setValue(440.0f);
osc.noteOn(0);
//create the scene
scene = new Scene(browser, 750, 500, Color.web("#666970"));
stage.setScene(scene);
stage.show();
}
}maven依赖于GWT元素:
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-elemental</artifactId>
<version>2.8.0</version>
</dependency>或者您知道用于DOM操作的替代/高级JAVA (即构建在JSObject层次结构上)吗?
发布于 2017-01-17 06:43:47
我就是你在评论中提到的试图将Elemental移植到JavaFx的人。我用它做了一个名为“动画陪伴”的小应用程序,它没有那么好。与WebKit一起提供的JavaFx引擎缺少了许多特性,而且将大量数据从JavaFx转移到JavaScript和返回非常缓慢。JavaFx人员重写了WebKit以依赖JavaFx进行呈现,有时还会出现一点不匹配,如果您太用力地推动UI,就会导致系统崩溃或耗尽资源。此外,Elemental本身也有点过时,有很多特定于WebKit的功能、缺少的特性和其他bug。
来自我的github的测试JavaFx代码要求您首先构建元素。我不太记得怎么做了。我认为您只需进入元素目录并在那里运行ant,然后在某个地方得到一个gwt-elemental.jar文件输出,您可以将测试链接到其中。我已经暂时在http://www.user00.com/gwt-elemental.jar放了一个预置版本。您还需要GWT2.7中的gwt-user.jar提供的一些文件。我在http://www.user00.com/gwt-user-pruned.jar临时提供了这些文件。从这里开始,您可以使用以下内容创建一个网页:
Stage stage = ...
// Create the WebView
BorderPane border = new BorderPane();
WebView webView = new WebView();
final WebEngine engine = webView.getEngine();
border.setCenter(webView);
Scene scene = new Scene(border);
stage.setScene(scene);
stage.show();
// Redirect the alert handler to send output to stderr
engine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> msg) {
System.err.println(msg.getData());
}});
// Start up the Gwt module when the page has finished loading. Grab the window
// and document objects and stash them somewhere for use later.
engine.getLoadWorker().stateProperty().addListener(
new ChangeListener<Worker.State>() {
@Override
public void changed(ObservableValue<? extends State> ov,
State oldState, State newState) {
if (newState == Worker.State.SUCCEEDED) {
Window win = (Window)GwtFxBridge.wrapJs(engine.executeScript("window"));
// The web page is loaded, and you have the global window
// JS object, so you can start your UI now
}
}
});
// Load the main Gwt application web page
try {
engine.load(new File("ui/index.html").toURI().toURL().toExternalForm());
}
catch(MalformedURLException e)
{
throw new IllegalArgumentException("Misconfiguration error. Cannot find empty web page", e);
}我真的不建议沿着这条路走。只是对它的支持不够,您必须非常了解您的JavaScript和Java,才能调试您将要面临的问题。我觉得倒转更有意义。运行nw.js作为驱动应用程序的主要VM运行JavaScript,如果需要执行Java操作,则按需要调用Java。您甚至可以使用GWT从Java代码生成JavaScript。
发布于 2017-01-15 19:16:11
是的,有一个,非常接近你已经发现的。它被称为GWT元素。虽然它是GWT,但它确实直接在DOM上,非常完整,并且真的很像直接在DOM上的薄冰。我正在使用它在https://github.com/nielsbaloe/vertxui上编写一个100%的java 100%异步框架https://github.com/nielsbaloe/vertxui。
https://stackoverflow.com/questions/41488110
复制相似问题