Question: What will be printed if the user clicks button 1 , button 1 again, then button 2 ? public class ButtonApp extends Application { private

What will be printed if the user clicks button 1, button 1 again, then button 2? public class ButtonApp extends Application {
private boolean enabled = false;
@override
public void start(Stage primaryStage){
Button button1= new Button("Enable");
button1.setOnAction(e ->{
enabled = true;
System.out.println("Enabled: "+ enabled);
});
Button button2= new Button("Check Enabled");
button2.setOnAction(e ->{
if (enabled){
System.out.println("The app is enabled.");
} else {
System.out.println("The app is disabled.");
}
});
VBox layout = new VBox(10);
layout.getChildren().addAll(button1, button2);
Scene scene = new Scene(layout,300,200);
primaryStage.setScene(scene);
primaryStage.setTitle("Button Listener Example");
primaryStage.show();
}
public static void main(String[] args){
launch(args);
}
}
What will be printed if the user clicks button 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!