**15.6 (Alternate two messages) Write a program to display the text Java is fun and Java is powerful alternately with a mouse click.
package section_15;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class _06 extends Application {
public void start(Stage primaryStage) {
String text1 = "Java is fun";
String text2 = "Java is powerful";
Text text = new Text();
text.setText(text1);
text.setOnMouseClicked(event -> {
if (text.getText().equals(text1)) {
text.setText(text2);
} else {
text.setText(text1);
}
});
StackPane pane = new StackPane(text);
Scene scene = new Scene(pane, 400, 200);
primaryStage.setTitle("_15_06");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}