在此示例中,WebView可能会加载内容,但不会显示它。但是,如果内容是自动播放youtube视频,则会发出声音。我认为问题与初始化有关。
Controller_mini.java:
package sample;
//some imports here
public class Controller_mini implements Initializable {
@FXML
WebView film_haqqinda_webview = new WebView();
public void pramoy_webview(ActionEvent event){
try {
Parent root2 = FXMLLoader.load(getClass().getResource("Film_haqqinda.fxml"));
Scene scene = new Scene(root2);
Stage window = (Stage) ((Node) event.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
window.centerOnScreen();
film_haqqinda_webview.getEngine().load("https://www.youtube.com/watch?v=Q-h8g9TLsks");
} catch (Exception e){}
}
public void filmlerin_siy_goster(){
String SQL = "select * from filmler;";
try {
ResultSet resultSet = Objects.requireNonNull(sample.JDBCConnect.ConnectDB()).createStatement().executeQuery(SQL);
ObservableList<String> films = FXCollections.observableArrayList();
while(resultSet.next()){
films.add(resultSet.getString(1));
}
} catch (Exception e) {
System.out.println("filmlerin siyahisini tesvir etmek alinmadi");
}
}
public void describe_kassirler() {
}
@Override
public void initialize(URL location, ResourceBundle resources) {
describe_kassirler();
filmlerin_siy_goster();
}
}
Log_in_screen.fxml中的按钮:
<Button layoutX="210.0" layoutY="202.0" mnemonicParsing="false" onAction="#pramoy_webview" text="Log in">
<font>
<Font size="18.0" />
</font>
</Button>
Film_haqqinda.fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.web.WebView?>
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="500.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.181" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller_mini">
<children>
<WebView fx:id="film_haqqinda_webview" layoutX="69.0" layoutY="56.0" prefHeight="325.0" prefWidth="621.0" />
</children>
</Pane>