JavaFX z Arią - powrót do strony głównej

Uruchomienie animowanego GIF-a w HTML5

Klasa Listing31c_03

Ściągnij klasę Listing31c_03.zip

package rozdzial31c;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

import java.net.URL;

public class Listing31c_03 extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        try {
            VBox root = new VBox();
            WebView wv = new WebView();
            WebEngine we = wv.getEngine();
            URL url = this.getClass().getClassLoader().
                      getResource("rozdzial31c/gifs.html");
            System.out.println(url);
            if (url != null) {
                we.load(url.toExternalForm());
            }
            root.getChildren().add(wv);
            Scene scene = new Scene(root, 454, 567);
            stage.setScene(scene);
            stage.setTitle("Animowany gif");
            stage.setOnCloseRequest(e -> Platform.exit());
            stage.show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Po uruchomieniu zobaczymy odpalonego animowanego GIF-a

zaba-smut