0

我在java中制作了一个小脚本,它应该打开一个加载特定.html文件的全屏webview,该程序应该在linux上运行,但似乎并非如此。这是我用来打开网络视图的代码:

public class MainBrowser extends Application {
    private Scene scene;
    @Override 
    public void start(Stage stage) {
        // create the scene
        stage.setTitle("Web View");

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();

        scene = new Scene(new Browser(),width,height, Color.web("#666970"));
        stage.setScene(scene);
        //scene.getStylesheets().add("webviewsample/BrowserToolbar.css");
        stage.setFullScreen(true);
        stage.show();
    }

    public static void main(){
        launch();
    }
}

package monitor;

import java.io.File;
import java.net.URL;

import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;


class Browser extends Region {

    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();

    public Browser() {
        //apply the styles
        getStyleClass().add("browser");
        // load the web page
        File openpage = new File(Config.PAGE_LOCAL_URL);
        webEngine.load(openpage.toURI().toString());
        //add the web view to the scene
        getChildren().add(browser);

    }
    private Node createSpacer() {
        Region spacer = new Region();
        HBox.setHgrow(spacer, Priority.ALWAYS);
        return spacer;
    }

    @Override protected void layoutChildren() {
        double w = getWidth();
        double h = getHeight();
        layoutInArea(browser,0,0,w,h,0, HPos.CENTER, VPos.CENTER);
    }

    @Override protected double computePrefWidth(double height) {
        return 750;
    }

    @Override protected double computePrefHeight(double width) {
        return 500;
    }
}

它似乎在 Windows 上工作得很好,但是当我在 linux 上运行程序时它会冻结,我什至没有遇到异常,它只是被冻结关闭。这是我第一次处理linux,我希望比我更专业的人能帮助我理解问题所在。

4

0 回答 0