gpt4 book ai didi

JavaFX WebView 浏览器

转载 作者:行者123 更新时间:2023-12-02 22:12:35 31 4
gpt4 key购买 nike

package webviewbrowser;

import java.util.List;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.VPos;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewBrowser extends Application {

@Override public void start(Stage primaryStage) throws Exception {
Pane root = new WebViewPane();
primaryStage.setScene(new Scene(root, 1024, 768));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}

/**
* Create a resizable WebView pane
*/
public class WebViewPane extends Pane {

public WebViewPane() {
VBox.setVgrow(this, Priority.ALWAYS);
setMaxWidth(Double.MAX_VALUE);
setMaxHeight(Double.MAX_VALUE);

WebView view = new WebView();
view.setMinSize(500, 400);
view.setPrefSize(500, 400);
final WebEngine eng = view.getEngine();
eng.load("http://www.google.com");
final TextField locationField = new TextField("http://www.google.com");
locationField.setMaxHeight(Double.MAX_VALUE);
Button goButton = new Button("Go");
goButton.setDefaultButton(true);
EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
eng.load(locationField.getText().startsWith("http://") ? locationField.getText() :
"http://" + locationField.getText());
}
};
goButton.setOnAction(goAction);
locationField.setOnAction(goAction);
eng.locationProperty().addListener(new ChangeListener<String>() {
@Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
locationField.setText(newValue);
}
});
GridPane grid = new GridPane();
grid.setVgap(5);
grid.setHgap(5);
GridPane.setConstraints(locationField, 0, 0, 1, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.SOMETIMES);
GridPane.setConstraints(goButton,1,0);
GridPane.setConstraints(view, 0, 1, 2, 1, HPos.CENTER, VPos.CENTER, Priority.ALWAYS, Priority.ALWAYS);
grid.getColumnConstraints().addAll(
new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.ALWAYS, HPos.CENTER, true),
new ColumnConstraints(40, 40, 40, Priority.NEVER, HPos.CENTER, true)
);
grid.getChildren().addAll(locationField, goButton, view);
getChildren().add(grid);
}

@Override protected void layoutChildren() {
List<Node> managed = getManagedChildren();
double width = getWidth();
double height = getHeight();
double top = getInsets().getTop();
double right = getInsets().getRight();
double left = getInsets().getLeft();
double bottom = getInsets().getBottom();
for (int i = 0; i < managed.size(); i++) {
Node child = managed.get(i);
layoutInArea(child, left, top,
width - left - right, height - top - bottom,
0, Insets.EMPTY, true, true, HPos.CENTER, VPos.CENTER);
}
}
}
}

这是我的代码。谁能帮我添加一个“停止”按钮来停止加载页面,添加标签来加载多个页面,并在我的浏览器中安装 Adob​​e Flash Player 以便我可以访问 Youtube(www.youtube.com)。

谢谢你帮助我。

我正在使用 Netbeans。当我运行我的应用程序时,这就是结果。

ant -f C:\\Users\\user\\Documents\\NetBeansProjects\\WebViewBrowser jfxsa-run
init:
Deleting: C:\Users\user\Documents\NetBeansProjects\WebViewBrowser\build\built-jar.properties
deps-jar:
Updating property file: C:\Users\user\Documents\NetBeansProjects\WebViewBrowser\build\built-jar.properties
compile:
Detected JavaFX Ant API version 1.2
Launching <fx:jar> task from C:\Program Files\Java\jdk1.7.0_09\lib\ant-javafx.jar
Launching <fx:deploy> task from C:\Program Files\Java\jdk1.7.0_09\lib\ant-javafx.jar
jfx-deployment:
jar:
run:
Device "Intel(R) HD Graphics Family" (\\.\DISPLAY1) initialization failed :
WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302

谁能告诉我为什么?

最佳答案

add tab to load multiple page

willow browser是一个选项卡式 JavaFX 浏览器示例项目 - 查看它以了解如何完成。

add a "Stop" Button to stop loading page,

您可以尝试在按钮的操作处理程序中执行 webView.getEngine().getLoadWorker().cancel();。我不确定 WebEngine 是否会尊重取消请求。

install Adobe Flash Player to my browser

你不能 - WebView 不支持 Flash 等插件。

access Youtube

使用 YouTube 的 html5 兼容视频播放界面,而不是基于 flash 的界面。

我创建了一些 sample code to play YouTube Videos in a WebView .

WARNING: bad driver version detected, device disabled. Please update your driver to at least version 8.15.10.2302

您的显示驱动程序已过时,不符合使用 JavaFX 的最低要求 - 您应该将其更新到较新的版本。

关于JavaFX WebView 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15006013/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com