package class6_3_JavaFXAndInnerClassDetails; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.effect.BoxBlur; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class Main1_NamedInnerClass_asBefore extends Application { private Label label; @Override public void start(Stage primaryStage) throws Exception{ Pane root = new StackPane(); label = new Label("This is a lot of text that will show up on the screen!"); Button clickMe = new Button("Click Me!"); clickMe.setOnAction(new MyHandler()); root.getChildren().addAll(label, clickMe); primaryStage.setTitle("Hello World"); primaryStage.setScene(new Scene(root, 300, 50)); primaryStage.show(); } public static void main(String[] args) { launch(args); // EventHandler handler = new MyHandler(); Main1_NamedInnerClass_asBefore instance = new Main1_NamedInnerClass_asBefore(); EventHandler handler2 = instance.new MyHandler(); } // If we make this inner class static, // we don't need any instances to create it, // but then we don't have a "this" reference // to the outer class, so we can't access label as easily. private /*static*/ class MyHandler implements EventHandler { public void handle(ActionEvent e) { System.out.println("The button was pressed!"); System.out.println(label.getText()); if(label.getEffect() == null) { label.setEffect(new BoxBlur()); } else { label.setEffect(null); } } } }