JavaFX 和 Java 互操作性

发布于 2024-07-09 09:42:44 字数 117 浏览 3 评论 0原文

我能否像使用 JavaFX Script 一样直接从 Java 中利用新 JavaFX API 提供的新功能?

所有底层 JavaFX API 都是纯 Java 或 JavaFX 脚本还是两者的混合?

Can I utilise the new functionality provided by the new JavaFX APIs directly from Java to the same extent as I would be able to using JavaFX Script?

Are all the underlying JavaFX APIs purely Java or JavaFX Script or a mix?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏花。依旧 2024-07-16 09:42:44

JavaFX API 是 JavaFX 和 Java 的混合体。 SDK附带了一个存档src.zip,其中包含部分API(仅包含最基本的类,但缺少javafx.scene之类的东西)。

AFAIK JavaFX 1.x 不正式支持从 Java 调用 JavaFX 代码。 JavaFX 博客中有一个博客条目,向您展示了如何使用不受支持的方法进行操作API,但是很复杂,在以后的版本中不会这样工作。

有两种支持的方法可以通过 Java 使用 JavaFX。 您可以使用脚本 API 调用 JavaFX 代码,如本文。 或者,恕我直言,这是最优雅的解决方案,使用 JavaFX 编写 API 访问代码,定义 Java 接口以与普通 Java 中的 JavaFX 代码交互,然后在 JavaFX 中实现这些接口。

The JavaFX APIs are a mix of JavaFX and Java. The SDK comes with an archive src.zip which contains a part of the APIs (only the most basic classes are included, but things like javafx.scene are missing).

Calling JavaFX code from Java is not officially supported in JavaFX 1.x AFAIK. There's a blog entry in the JavaFX blog that shows you how to do anyway it using unsupported APIs, but it's complicated and won't work this way in future versions.

There are two supported ways to use JavaFX from Java. Either you use the Scripting API to invoke JavaFX code, as shown in this article. Or, which is the most elegant solution IMHO, write the API-accessing code using JavaFX, define Java interfaces to interact with your JavaFX code from plain Java, and then implement those interfaces in JavaFX.

同展鸳鸯锦 2024-07-16 09:42:44

我们能够将多媒体组件与 JavaFX 结合使用,并取得了一些成功。 它们完全不受这种方式支持,并且可能会发生变化,类似于 JavaSE 中的 com.sun 包。

我们将它们集成到 Swing UI 中,并且能够直接从 Java 中完成您可以在 FX 中完成的 MM 操作。

希望他们尽快将其中一些放入核心库中。

We were able to use the multi-media components with JavaFX with some success. they are totally unsupported in this manner and subject to change similar to how the com.sun packages are in JavaSE.

We integrated them into a Swing UI and were able to do the MM stuff you could do from FX straight from Java.

Hope they put some of that in the core libraries soon.

凤舞天涯 2024-07-16 09:42:44

JavaFX 中使用的场景图是开源的。 您可以在这里查看(https://scenegraph.dev.java.net)。 虽然该站点尚未更新以反映 JavaFX 1.x 附带的最终版本,但您仍然可以使用 JavaFX SDK 附带的 jar 并在 swing 应用程序中混合场景图和 swing 节点。 但是,您会遇到一些困难,因为此版本的场景图没有官方 API。

这是使用 JavaFX 1.0 附带的场景图的“hello world”。 请记住在构建路径中包含“Scenario.jar”。

import java.awt.Color;
import java.awt.Paint;
import java.awt.geom.Point2D;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.sun.scenario.scenegraph.JSGPanel;
import com.sun.scenario.scenegraph.SGGroup;
import com.sun.scenario.scenegraph.fx.FXText;



public class HelloWorldScenario101 implements Runnable {



    /**
     * @param args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new HelloWorldScenario101());
    }



    public HelloWorldScenario101() {
        //
    }



    @Override
    public void run() {

        this.frame = new JFrame();
        this.panel = new JSGPanel();
        this.text = new FXText();
        this.paint = new Color(255, 0, 0, 255);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Hello World");
        frame.add(this.panel);
        frame.setContentPane(this.panel);
        scene = new SGGroup();
        this.text.setText("Hello World");
        this.text.setFillPaint(this.paint);
        this.text.setLocation(new Point2D.Float(10, 10));
        this.scene.add(this.text);
        this.panel.setScene(scene);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);

    }



    private JFrame frame;

    private JSGPanel panel;

    private SGGroup scene;

    private FXText text;

    private Paint paint;



}

The scenegraph used in JavaFX is opensource. You can check it here (https://scenegraph.dev.java.net). While the site hasn't been updated to reflect the final version shipped with JavaFX 1.x, you can still use the jar that comes with the JavaFX SDK and mix scenegraph and swing nodes inside your swing application. However, you'll have some difficulty because there's no official API for this version of scenegraph.

Here's a "hello world" using the scenegraph that comes woth JavaFX 1.0. Remember to include the "Scenario.jar" in your build path.

import java.awt.Color;
import java.awt.Paint;
import java.awt.geom.Point2D;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import com.sun.scenario.scenegraph.JSGPanel;
import com.sun.scenario.scenegraph.SGGroup;
import com.sun.scenario.scenegraph.fx.FXText;



public class HelloWorldScenario101 implements Runnable {



    /**
     * @param args
     */
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new HelloWorldScenario101());
    }



    public HelloWorldScenario101() {
        //
    }



    @Override
    public void run() {

        this.frame = new JFrame();
        this.panel = new JSGPanel();
        this.text = new FXText();
        this.paint = new Color(255, 0, 0, 255);

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("Hello World");
        frame.add(this.panel);
        frame.setContentPane(this.panel);
        scene = new SGGroup();
        this.text.setText("Hello World");
        this.text.setFillPaint(this.paint);
        this.text.setLocation(new Point2D.Float(10, 10));
        this.scene.add(this.text);
        this.panel.setScene(scene);
        frame.pack();
        frame.setLocationByPlatform(true);
        frame.setVisible(true);

    }



    private JFrame frame;

    private JSGPanel panel;

    private SGGroup scene;

    private FXText text;

    private Paint paint;



}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文