I am trying to create a GUI for a webcrawler. When they press the search button, I want a text to appear that says "Searching..."
public class Main extends Application {
private CrawlerTest c;
private Scene scene1, scene2;
private String urls;
private Text urlsText, searchText;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
this.c = new CrawlerTest();
primaryStage.setTitle("WebCrawler");
//layout1
TextField searchInput = new TextField();
TextField keyword = new TextField();
Label searchLabel = new Label("Website URL");
searchLabel.setLabelFor(searchInput);
Label keywordLabel = new Label("Search for keyword");
keywordLabel.setLabelFor(keyword);
Button searchButton = new Button();
searchButton.setText("Search!");
this.searchText = new Text("");
this.searchText.setFont(new Font(20));
searchButton.setOnAction(e -> {
if (this.checkURL(searchInput.getText())) {
this.searchText.setText("Searching... This may take a while.");
this.urls = this.c.run(searchInput.getText(), keyword.getText());
primaryStage.setScene(scene2);
this.urlsText.setText(this.urls);
}
else {
AlertError.display("Error!", "Entered URL format is incorrect");
}
});
FlowPane container = new FlowPane();
container.getChildren().addAll(searchInput, keyword, searchButton);
VBox layout1 = new VBox(10);
layout1.setPadding(new Insets(20, 20, 20, 20));
layout1.getChildren().addAll(searchLabel, searchInput, keywordLabel, keyword, this.searchText, searchButton);
scene1 = new Scene(layout1, 300, 250);
The problem is that
this.searchText.setText("Searching... This may take a while.");
does not change the text when it is in the if statement if (this.checkURL(searchInput.getText()))
but it does work outside of the if statement. I know this if statement is entered as I tried debugging it and it worked. Can someone help me change the text of searchText when the button is clicked? Thanks!