简体   繁体   English

如何初始化JavaFX Tookit?

[英]How To Initialize JavaFX Tookit?

I have a question. 我有个问题。

How does one initialize the JavaFX toolkit with the method I found in an earlier StackOverflow Question? 如何使用我在前面的StackOverflow问题中找到的方法初始化JavaFX工具包? The topic can be found here: JavaFX 2.1: Toolkit not initialized 可以在这里找到主题: JavaFX 2.1:未初始化的工具包

I am trying to use a solution similar to this solution from that thread: 我正在尝试使用与该线程类似的解决方案:

Problem: Non-trivial Swing GUI application needs to run JavaFX components. 问题:非平凡的Swing GUI应用程序需要运行JavaFX组件。 Application's startup process initializes the GUI after starting up a dependent service layer. 应用程序的启动过程会在启动相关服务层后初始化GUI。

Solutions Subclass JavaFX Application class and run it in a separate thread eg:* 解决方案子类JavaFX Application类,并在单独的线程中运行它,例如:*

public class JavaFXInitializer extends Application {
    @Override
    public void start(Stage stage) throws Exception {
        // JavaFX should be initialized
        someGlobalVar.setInitialized(true);
    }
}

The only problem I have is: What do I do with 我唯一的问题是:我该怎么办

someGlobalVar.setInitialized(true); ?

I don't know what to fill in there, and some tips would be appreciated :) 我不知道该在那填写什么,有些技巧将不胜感激:)

import com.sun.javafx.application.PlatformImpl;

public class JavaFXInitializer
{

        public JavaFXInitializer()
        {
            initFx();
        }
        private synchronized static void initFx() {
            PlatformImpl.startup(() -> {
            });
        }
}

I am writing this answer for the comment you have done about how to support ( .mp3,.wav,.flac,.ogg ) etc in java.For .mp3 you can use JLayer http://www.javazoom.net/projects.html search on web for examples. 我正在写此答案,以表达您对如何在Java中支持( .mp3,.wav,.flac,.ogg )等所做的评论。对于.mp3您可以使用JLayer http://www.javazoom.net/projects .html在网络上搜索示例。

About ( .mp3,.wav.flac,.ogg ) and some more you can use JavaZoom BasicPlayer which uses some external libraries to support them you can download the zip folder here (download without installer and you open the zip folder). 关于( .mp3,.wav.flac,.ogg )以及更多内容,您可以使用JavaZoom BasicPlayer ,它使用一些外部库来支持它们,您可以在这里下载zip文件夹(无需安装程序即可下载并打开zip文件夹)。

Then go on the folder lib and copy all the .jars except kj_dsp which can be used for visual representation on audio data and contains also a class about fast fourier transform(FFT).Also change MP3_SPI1.9.3 with MP3SPI1.9.4 然后转到文件夹lib并复制除可用于音频数据的可视表示的kj_dsp以外的所有.jar文件 ,其中还包含有关快速傅立叶变换(FFT)的类。还可以用MP3SPI1.9.4更改MP3_SPI1.9.3。

Then add these .jars into your project libraries and just use: 然后将这些.jars添加到您的项目库中,然后使用:

BasicPlayer player = new BasicPlayer();

The whole thing uses Service Provider Interface (SPI) mechanism. 整个过程使用服务提供者接口(SPI)机制。

It runs on a separate thread so you don't have to worry.It works really well but the project is a little bit old.It's a good start!About docs check the website. 它运行在一个单独的线程上,因此您不必担心。它确实运行良好,但项目有点旧。这是一个不错的开始!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM