JavaFX WebEngine is not tracked in blog statistics of wordpress - wordpress

I have notice that a visit from a JavaFx WebEngine is not tracked in the statistics of the website/blog.
Thats the code i use. The website is loaded but if I check my statistics in the wordpress-administration-tool, there is not any visit tracked.
public class Example extends Application {
#Override
public void start(Stage stage) throws Exception {
BorderPane borderPane = new BorderPane();
WebView browser = new WebView();
WebEngine webEngine = browser.getEngine();
borderPane.setCenter(browser);
webEngine.load("https://somewordpressblog.wordpress.com/");
Scene scene = new Scene(borderPane, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Does anyone know why?

Related

live video streaming from url in javafx

I want to show live streaming video from url in javafx. I am using webview.
It is showing only text in that webpage. It is not showing live video streaming. Please suggest me a way to do that.
public class A extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
WebView webView = new WebView();
webView.getEngine().load("http://192.168.0.143:8000/");
VBox vbox = new VBox(webView);
Scene scene = new Scene(vbox);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}

How to call the public void start(Stage primaryStage) Method from a different class

I'am new to JavaFX, so my coding is not the best. My programme has one Stage with 2 different Scenes. For a better overview I have created a new class for the second Scene. From this second Scene I want to go back to first one, using a button. The method: primaryStage.setScene(scene) is not working and I dont know why. Can someone please help me? :)
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
GridPane primarygridpane = new GridPane();
Scene scene = new Scene(primarygridpane,400,400);
...
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
public class Harnwegsinfektion {
public static void create (Stage primaryStage){
GridPane secondarygridpane = new GridPane();
Scene scene2 = new Scene(secondarygridpane,400,400);
buttonBack.setOnAction(new EventHandler<ActionEvent>(){
#Override
public void handle(ActionEvent e) {
primaryStage.setScene(scene);
}
});
primaryStage.setScene(scene2);
primaryStage.show();
}
}
The problem is that your scene variable is named scene2 and you are calling setScene() with scene.
I don't really know when and where create() is called, but if you want to go back to the first scene from the button, you have to save the original one before switching :
public static void create (Stage primaryStage){
GridPane secondarygridpane = new GridPane();
Scene scene2 = new Scene(secondarygridpane,400,400);
Scene originalScene=primaryStage.getScene(); //save the previous scene
buttonBack.setOnAction(new EventHandler<ActionEvent>(){
#Override
public void handle(ActionEvent e) {
primaryStage.setScene(originalScene); //go back to the previous scene
}
});
primaryStage.setScene(scene2);
primaryStage.show();
}

How do I load to default website when inactive [duplicate]

This question already has answers here:
Passing Parameters JavaFX FXML
(10 answers)
Closed 3 years ago.
I am trying to do a WebView that surf websites. When the program is inactive for few seconds, the WebViewwill load back to the beginning of the website.
JavaFXApplication13.java
#Override
public void start(Stage stage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("main.fxml"));
stage.setScene(new Scene(root));
stage.show();
Duration duration = Duration.seconds(10);
PauseTransition transition = new PauseTransition(duration);
transition.setOnFinished(evt -> inactive());
stage.addEventFilter(InputEvent.ANY, evt -> transition.playFromStart());
transition.play();
}
private void inactive(){
//to investigate if it inactive
System.out.println("Inactive once");
//load other website when inactive ?
}
MainController.java
#FXML
WebView webview;
private WebEngine webEngine;
#Override
public void initialize(URL url, ResourceBundle rb) {
webEngine = webview.getEngine();
webview.setContextMenuEnabled(false);
webEngine.load("http://www.google.com");}
This is my main.fxml
https://drive.google.com/open?id=1_WnWhkbjaX1s2Y2jI0ojIvc2aQC1njJh
You could access the webview from the controller
FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent root = loader.load();
MainController controller = loader.getController();
controller.loadDefaultSite();
And in the MainController make a Function
public void loadDefaultSite() {
webEngine.load("http://www.google.com");
}
Example:
private MainController controller;
#Override
public void start(Stage stage) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent root = loader.load();
controller = loader.getController();
stage.setScene(new Scene(root));
stage.show();
Duration duration = Duration.seconds(10);
PauseTransition transition = new PauseTransition(duration);
transition.setOnFinished(evt -> inactive());
stage.addEventFilter(InputEvent.ANY, evt -> transition.playFromStart());
transition.play();
}
private void inactive(){
//check if site is already default...
controller.loadDefaultSite();
}

Switching scenes in JavaFX(FXML) error

So, I'm trying to switch scenes in JavaFX but I can't seem to get it to work when I hard coded it I was able to get it working by using lambda expressions.
public class Main extends Application {
Stage window;
Scene scene1;
Scene scene2;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
window = primaryStage;
Label label = new Label("Welcome to the first scene");
Button bttn1 = new Button("Go to second scene");
bttn1.setOnAction(e -> window.setScene(scene2));
//Scene 1
VBox layout1 = new VBox(20);
layout1.getChildren().addAll(label, bttn1);
scene1 = new Scene(layout1, 400, 400);
//Scene 2
Button bttn2 = new Button("Go to first scene");
bttn2.setOnAction(e -> window.setScene(scene1));
StackPane layout2 = new StackPane();
layout2.getChildren().add(bttn2);
scene2 = new Scene(layout2, 400, 500);
window.setScene(scene1);
window.setTitle("Test");
window.show();
}
However the project involves a few different GUIs and I would prefer to design the GUI's in FXML Scene Builder than to hardcode them the FX way. However when I have tried to do the FXML way it hasn't worked an error is always appearing when I press the button.
Error message
This is the document controller code.
public class FXMLDocumentController implements Initializable {
#FXML
private Button button1;
#FXML
private Button button2;
#FXML
private void handleButtonAction(ActionEvent event) throws IOException {
Stage stage;
Parent root;
if(event.getSource() == button1){
stage=(Stage)button1.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXML2.fxml"));
}
else{
stage=(Stage)button2.getScene().getWindow();
root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
}
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
}
}
The error you posted says the code is trying to load a button as an anchor pane. Check too see if you have an anchorpane with the fx:I'd of button1.

action on a Video Tag webview, Javafx

I work on a javafx project. I have this code.
public class MoviePlayer extends Application{
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage stage) throws Exception
{
WebView root = new WebView();
root.getEngine().loadContent(
"<video width='320' height='240'controls='controls' >" +
"<source src='file:///C:/Users/lenovo-pc/workspace/EnhanceVideoJava/Movie_0001_512kb.mp4'/>" +
"Your browser does not support the video tag." +
"</video> ");
stage.setScene(new Scene(root, 500, 400));
stage.show();
}}
Now, I want to create an action when i click on the video. Is it possible??
Tanks

Resources