简体   繁体   中英

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? The topic can be found here: JavaFX 2.1: Toolkit not initialized

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. Application's startup process initializes the GUI after starting up a dependent service layer.

Solutions Subclass JavaFX Application class and run it in a separate thread eg:*

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.

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).

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

Then add these .jars into your project libraries and just use:

BasicPlayer player = new BasicPlayer();

The whole thing uses Service Provider Interface (SPI) mechanism.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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