Idea behind this is to have a "Search" textfield. When user types in some data and clicks on a button. Another window opens with data according to typed into "Search" textfield.
I create my textfield like this TextField search = new TextField();
On a button click I do this:
searchButton.setOnAction(e -> {
String st = search.getText().toString();
System.out.println(search.getText());
setSt(st);
InfoWindow.display("Detailed information on " + st);
});
setSt() method looks like this:
public void setSt(String st)
{
this.st = st;
}
this.st
is declared like this: private static String st;
In the informational window class I try to evaluate what user typed in:
public static void display(String title){
Stage window = new Stage();
window.initModality(Modality.APPLICATION_MODAL);
window.setTitle(title);
window.setMinWidth(250);
String st = MainClass.getSt();
if(st == "M16"){
textLabel = new Label("The M16 rifle, officially designated Rifle, Caliber 5.56 mm.\n" +
" M16, is a United States military adaptation of the Armalite AR-15 rifle.\n" +
"The original M16 was a select-fire, 5.56×45mm rifle with a 20-round magazine.");
}
VBox layout = new VBox(10);
layout.getChildren().addAll(textLabel);
layout.setAlignment(Pos.CENTER);
Scene scene = new Scene(layout);
window.setScene(scene);
window.showAndWait();
}
getSt() method looks like this:
public static String getSt()
{
return st;
}
I've went through the program flow with the help of the debugger. It get's to the point of evaluation if(st == "M16")
and I can see in debugger that st = "M16"(because I've typed that in "Search" textfield), but it doesn't get into the 'if', it just continues as if condition would be false. What could be the problem here? Can you help to figure it out? It is definitely not in the reach of my knowledge.