{"id":"gui-views-changing-center","slug":"changing-center","title":"One frame, changing content","text":"`setScene` swaps everything in the window. Many applications keep part of the window in place instead, such as a menu along the top, and change only the area under it. A BorderPane (module 48) fits that well: the menu goes in the top region, the content in the center, and a handler swaps the center with `setCenter`.\n\n### A guide with a menu\n\nA castle's visitor guide has three pages, chosen from a menu:\n\n```java\nimport javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label hall = new Label(\"The great hall seats 200 guests under an oak roof.\");\n        Label tower = new Label(\"The north tower has 147 steps and a view over the river.\");\n        Label kitchens = new Label(\"The kitchens once baked bread for the whole village.\");\n\n        Button toHall = new Button(\"Great hall\");\n        Button toTower = new Button(\"Tower\");\n        Button toKitchens = new Button(\"Kitchens\");\n        HBox menu = new HBox(10, toHall, toTower, toKitchens);\n        menu.setPadding(new Insets(10));\n\n        BorderPane frame = new BorderPane();\n        frame.setTop(menu);\n        frame.setCenter(hall);\n\n        toHall.setOnAction(event -> frame.setCenter(hall));\n        toTower.setOnAction(event -> frame.setCenter(tower));\n        toKitchens.setOnAction(event -> frame.setCenter(kitchens));\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Castle guide\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n```\n\n```window\n{\"events\":[\"click Button \\\"Tower\\\"\"],\"window\":{\"windows\":[{\"title\":\"Castle guide\",\"scene\":{\"root\":{\"n\":1,\"type\":\"BorderPane\",\"top\":{\"n\":2,\"type\":\"HBox\",\"padding\":[10,10,10,10],\"spacing\":10,\"children\":[{\"n\":3,\"type\":\"Button\",\"text\":\"Great hall\",\"onAction\":true},{\"n\":4,\"type\":\"Button\",\"text\":\"Tower\",\"onAction\":true},{\"n\":5,\"type\":\"Button\",\"text\":\"Kitchens\",\"onAction\":true}]},\"center\":{\"n\":6,\"type\":\"Label\",\"text\":\"The north tower has 147 steps and a view over the river.\"}}}}],\"problems\":[]},\"outline\":\"Window \\\"Castle guide\\\"\\n  BorderPane\\n    top: HBox spacing 10, padding 10\\n      Button \\\"Great hall\\\"\\n      Button \\\"Tower\\\"\\n      Button \\\"Kitchens\\\"\\n    center: Label \\\"The north tower has 147 steps and a view over the river.\\\"\"}\n```\n\n- The three pages are made at the start and kept in variables. Only one of them is in the window at a time: the center region holds one node, and `setCenter` puts another one in its place.\n- The page that is taken out isn't destroyed. The variable still refers to it, and the next click on its button puts it back.\n- `start` calls `frame.setCenter(hall)` before the window shows, so the guide opens on a page and not on an empty middle. A view the user sees first is the **default** view.\n- The menu, the scene and the stage stay the same the whole time. Only the center changes.\n\n### Pages with more in them\n\nA page can be any node, so it can be a whole layout with its own buttons and handlers. The front desk of the castle uses the guide to sell tickets too. Its pages are built by helper methods (module 48), once each:\n\n```java\nimport javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.scene.layout.VBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n    private int tickets;\n\n    @Override\n    public void start(Stage stage) {\n        VBox hall = hallPage();\n        VBox sales = ticketPage();\n\n        Button toHall = new Button(\"Great hall\");\n        Button toTickets = new Button(\"Tickets\");\n        HBox menu = new HBox(10, toHall, toTickets);\n        menu.setPadding(new Insets(10));\n\n        BorderPane frame = new BorderPane();\n        frame.setTop(menu);\n        frame.setCenter(hall);\n        toHall.setOnAction(event -> frame.setCenter(hall));\n        toTickets.setOnAction(event -> frame.setCenter(sales));\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Castle front desk\");\n        stage.show();\n    }\n\n    private VBox hallPage() {\n        VBox page = new VBox(6, new Label(\"The great hall seats 200 guests.\"), new Label(\"Open daily from 10 to 17.\"));\n        page.setPadding(new Insets(10));\n        return page;\n    }\n\n    private VBox ticketPage() {\n        Label sold = new Label(\"Tickets sold today: 0\");\n        Button sell = new Button(\"Sell a ticket\");\n        sell.setOnAction(event -> {\n            this.tickets++;\n            sold.setText(\"Tickets sold today: \" + this.tickets);\n        });\n        VBox page = new VBox(6, sold, sell);\n        page.setPadding(new Insets(10));\n        return page;\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n```\n\n```window\n{\"events\":[\"click Button \\\"Tickets\\\"\",\"click Button \\\"Sell a ticket\\\"\",\"click Button \\\"Sell a ticket\\\"\",\"click Button \\\"Great hall\\\"\",\"click Button \\\"Tickets\\\"\"],\"window\":{\"windows\":[{\"title\":\"Castle front desk\",\"scene\":{\"root\":{\"n\":1,\"type\":\"BorderPane\",\"top\":{\"n\":2,\"type\":\"HBox\",\"padding\":[10,10,10,10],\"spacing\":10,\"children\":[{\"n\":3,\"type\":\"Button\",\"text\":\"Great hall\",\"onAction\":true},{\"n\":4,\"type\":\"Button\",\"text\":\"Tickets\",\"onAction\":true}]},\"center\":{\"n\":5,\"type\":\"VBox\",\"padding\":[10,10,10,10],\"spacing\":6,\"children\":[{\"n\":6,\"type\":\"Label\",\"text\":\"Tickets sold today: 2\"},{\"n\":7,\"type\":\"Button\",\"text\":\"Sell a ticket\",\"onAction\":true}]}}}}],\"problems\":[]},\"outline\":\"Window \\\"Castle front desk\\\"\\n  BorderPane\\n    top: HBox spacing 10, padding 10\\n      Button \\\"Great hall\\\"\\n      Button \\\"Tickets\\\"\\n    center: VBox spacing 6, padding 10\\n      Label \\\"Tickets sold today: 2\\\"\\n      Button \\\"Sell a ticket\\\"\"}\n```\n\nThe ticket page was out of the window for a while, but it comes back as it was, with `Tickets sold today: 2`: it's the same VBox with the same label. The window as text shows the page indented under `center:`, with its own children under it.\n\n### setScene or setCenter?\n\nBoth switch views, and they fit different windows:\n\n- `stage.setScene(...)` replaces everything in the window. It suits views that share nothing, such as a login form and the program behind it, or step 1's settings.\n- `frame.setCenter(...)` keeps the rest of the BorderPane: a menu in the top region, a status line at the bottom. It suits an application whose views are always one click away.\n","task":"A funfair's info screen. The four pages (labels) and the four menu buttons are made already, and so is an empty BorderPane. Finish the window:\n\n- top: an HBox with the spacing 10 and the padding 10 on every side, holding the buttons `Rides`, `Food`, `Hours` and `Prices`, in that order\n- center: the page of the button clicked last: Rides shows `The roller coaster reopens on Friday.`, Food shows `Pancakes and soup by the big wheel.`, Hours shows `Open daily from 10 to 20.`, and Prices shows `One ride costs 4 tokens.`\n- at the start, the center shows the rides page\n\nThe window's title is `Funfair`. The task card shows the window after a click on Food.\n","kind":"code","seed":"import javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label rides = new Label(\"The roller coaster reopens on Friday.\");\n        Label food = new Label(\"Pancakes and soup by the big wheel.\");\n        Label hours = new Label(\"Open daily from 10 to 20.\");\n        Label prices = new Label(\"One ride costs 4 tokens.\");\n        Button toRides = new Button(\"Rides\");\n        Button toFood = new Button(\"Food\");\n        Button toHours = new Button(\"Hours\");\n        Button toPrices = new Button(\"Prices\");\n\n        BorderPane frame = new BorderPane();\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Funfair\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","solution":"import javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label rides = new Label(\"The roller coaster reopens on Friday.\");\n        Label food = new Label(\"Pancakes and soup by the big wheel.\");\n        Label hours = new Label(\"Open daily from 10 to 20.\");\n        Label prices = new Label(\"One ride costs 4 tokens.\");\n        Button toRides = new Button(\"Rides\");\n        Button toFood = new Button(\"Food\");\n        Button toHours = new Button(\"Hours\");\n        Button toPrices = new Button(\"Prices\");\n\n        BorderPane frame = new BorderPane();\n        HBox menu = new HBox(10, toRides, toFood, toHours, toPrices);\n        menu.setPadding(new Insets(10));\n        frame.setTop(menu);\n        frame.setCenter(rides);\n\n        toRides.setOnAction(event -> frame.setCenter(rides));\n        toFood.setOnAction(event -> frame.setCenter(food));\n        toHours.setOnAction(event -> frame.setCenter(hours));\n        toPrices.setOnAction(event -> frame.setCenter(prices));\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Funfair\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","hints":["Put the four buttons in an HBox with the spacing 10 and the padding 10, place that HBox in the frame's top region, and put the rides page in the center before the window shows. Then give each button a handler that puts its own page in the center.","The menu: `HBox menu = new HBox(10, toRides, toFood, toHours, toPrices);`, then `menu.setPadding(new Insets(10));`, `frame.setTop(menu);` and `frame.setCenter(rides);`. A handler: `toFood.setOnAction(event -> frame.setCenter(food));`, and the same for the other three."],"tests":[{"name":"Test 1","stdin":"","expect":"","hidden":false,"events":["click Button \"Food\""],"window":{"windows":[{"title":"Funfair","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Rides","onAction":true},{"n":4,"type":"Button","text":"Food","onAction":true},{"n":5,"type":"Button","text":"Hours","onAction":true},{"n":6,"type":"Button","text":"Prices","onAction":true}]},"center":{"n":7,"type":"Label","text":"Pancakes and soup by the big wheel."}}}}],"problems":[]},"outline":"Window \"Funfair\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Rides\"\n      Button \"Food\"\n      Button \"Hours\"\n      Button \"Prices\"\n    center: Label \"Pancakes and soup by the big wheel.\""},{"name":"Test 2","stdin":"","expect":"","hidden":true,"events":[],"window":{"windows":[{"title":"Funfair","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Rides","onAction":true},{"n":4,"type":"Button","text":"Food","onAction":true},{"n":5,"type":"Button","text":"Hours","onAction":true},{"n":6,"type":"Button","text":"Prices","onAction":true}]},"center":{"n":7,"type":"Label","text":"The roller coaster reopens on Friday."}}}}],"problems":[]},"outline":"Window \"Funfair\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Rides\"\n      Button \"Food\"\n      Button \"Hours\"\n      Button \"Prices\"\n    center: Label \"The roller coaster reopens on Friday.\""},{"name":"Test 3","stdin":"","expect":"","hidden":true,"events":["click Button \"Hours\"","click Button \"Rides\""],"window":{"windows":[{"title":"Funfair","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Rides","onAction":true},{"n":4,"type":"Button","text":"Food","onAction":true},{"n":5,"type":"Button","text":"Hours","onAction":true},{"n":6,"type":"Button","text":"Prices","onAction":true}]},"center":{"n":7,"type":"Label","text":"The roller coaster reopens on Friday."}}}}],"problems":[]},"outline":"Window \"Funfair\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Rides\"\n      Button \"Food\"\n      Button \"Hours\"\n      Button \"Prices\"\n    center: Label \"The roller coaster reopens on Friday.\""},{"name":"Test 4","stdin":"","expect":"","hidden":true,"events":["click Button \"Prices\""],"window":{"windows":[{"title":"Funfair","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Rides","onAction":true},{"n":4,"type":"Button","text":"Food","onAction":true},{"n":5,"type":"Button","text":"Hours","onAction":true},{"n":6,"type":"Button","text":"Prices","onAction":true}]},"center":{"n":7,"type":"Label","text":"One ride costs 4 tokens."}}}}],"problems":[]},"outline":"Window \"Funfair\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Rides\"\n      Button \"Food\"\n      Button \"Hours\"\n      Button \"Prices\"\n    center: Label \"One ride costs 4 tokens.\""},{"name":"Test 5","stdin":"","expect":"","hidden":true,"events":["click Button \"Food\"","click Button \"Food\"","click Button \"Hours\""],"window":{"windows":[{"title":"Funfair","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Rides","onAction":true},{"n":4,"type":"Button","text":"Food","onAction":true},{"n":5,"type":"Button","text":"Hours","onAction":true},{"n":6,"type":"Button","text":"Prices","onAction":true}]},"center":{"n":7,"type":"Label","text":"Open daily from 10 to 20."}}}}],"problems":[]},"outline":"Window \"Funfair\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Rides\"\n      Button \"Food\"\n      Button \"Hours\"\n      Button \"Prices\"\n    center: Label \"Open daily from 10 to 20.\""}],"require":[],"forbid":[],"more":[{"task":"A city bike app has a menu that shows its pages in the center of a BorderPane. Make the menu show where the user is: the button of the page that is showing is **disabled**, and the other two are enabled. `setDisable(true)` disables a button, and `setDisable(false)` enables it again (module 49). A disabled button does nothing when it's clicked.\n\nThe app opens on the prices page, so `Prices` starts disabled. A click on `Stations` shows the stations page, disables `Stations` and enables the other two, and so on. Don't change anything else: the pages, the menu and the texts stay as they are. The task card shows the window after a click on Stations.\n","kind":"code","seed":"import javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label prices = new Label(\"A ride of 30 minutes costs 1 euro.\");\n        Label stations = new Label(\"There are 42 stations around the city.\");\n        Label help = new Label(\"A bike is broken? Leave it at a station and press its red button.\");\n\n        Button toPrices = new Button(\"Prices\");\n        Button toStations = new Button(\"Stations\");\n        Button toHelp = new Button(\"Help\");\n        HBox menu = new HBox(10, toPrices, toStations, toHelp);\n        menu.setPadding(new Insets(10));\n\n        BorderPane frame = new BorderPane();\n        frame.setTop(menu);\n        frame.setCenter(prices);\n\n        toPrices.setOnAction(event -> frame.setCenter(prices));\n        toStations.setOnAction(event -> frame.setCenter(stations));\n        toHelp.setOnAction(event -> frame.setCenter(help));\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"City bikes\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","solution":"import javafx.application.Application;\nimport javafx.geometry.Insets;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.scene.layout.HBox;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label prices = new Label(\"A ride of 30 minutes costs 1 euro.\");\n        Label stations = new Label(\"There are 42 stations around the city.\");\n        Label help = new Label(\"A bike is broken? Leave it at a station and press its red button.\");\n\n        Button toPrices = new Button(\"Prices\");\n        Button toStations = new Button(\"Stations\");\n        Button toHelp = new Button(\"Help\");\n        HBox menu = new HBox(10, toPrices, toStations, toHelp);\n        menu.setPadding(new Insets(10));\n\n        BorderPane frame = new BorderPane();\n        frame.setTop(menu);\n        frame.setCenter(prices);\n        toPrices.setDisable(true);\n\n        toPrices.setOnAction(event -> {\n            frame.setCenter(prices);\n            toPrices.setDisable(true);\n            toStations.setDisable(false);\n            toHelp.setDisable(false);\n        });\n        toStations.setOnAction(event -> {\n            frame.setCenter(stations);\n            toPrices.setDisable(false);\n            toStations.setDisable(true);\n            toHelp.setDisable(false);\n        });\n        toHelp.setOnAction(event -> {\n            frame.setCenter(help);\n            toPrices.setDisable(false);\n            toStations.setDisable(false);\n            toHelp.setDisable(true);\n        });\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"City bikes\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","hints":["Before the window shows, disable the button of the default page: `toPrices.setDisable(true);`.","Each handler now has a body in braces: it sets the center, then calls `setDisable` on all three buttons, `true` for its own and `false` for the other two."],"tests":[{"name":"Test 1","stdin":"","expect":"","hidden":false,"events":["click Button \"Stations\""],"window":{"windows":[{"title":"City bikes","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Prices","onAction":true},{"n":4,"type":"Button","text":"Stations","disable":true,"onAction":true},{"n":5,"type":"Button","text":"Help","onAction":true}]},"center":{"n":6,"type":"Label","text":"There are 42 stations around the city."}}}}],"problems":[]},"outline":"Window \"City bikes\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Prices\"\n      Button \"Stations\" (disabled)\n      Button \"Help\"\n    center: Label \"There are 42 stations around the city.\""},{"name":"Test 2","stdin":"","expect":"","hidden":true,"events":[],"window":{"windows":[{"title":"City bikes","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Prices","disable":true,"onAction":true},{"n":4,"type":"Button","text":"Stations","onAction":true},{"n":5,"type":"Button","text":"Help","onAction":true}]},"center":{"n":6,"type":"Label","text":"A ride of 30 minutes costs 1 euro."}}}}],"problems":[]},"outline":"Window \"City bikes\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Prices\" (disabled)\n      Button \"Stations\"\n      Button \"Help\"\n    center: Label \"A ride of 30 minutes costs 1 euro.\""},{"name":"Test 3","stdin":"","expect":"","hidden":true,"events":["click Button \"Help\"","click Button \"Prices\""],"window":{"windows":[{"title":"City bikes","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Prices","disable":true,"onAction":true},{"n":4,"type":"Button","text":"Stations","onAction":true},{"n":5,"type":"Button","text":"Help","onAction":true}]},"center":{"n":6,"type":"Label","text":"A ride of 30 minutes costs 1 euro."}}}}],"problems":[]},"outline":"Window \"City bikes\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Prices\" (disabled)\n      Button \"Stations\"\n      Button \"Help\"\n    center: Label \"A ride of 30 minutes costs 1 euro.\""},{"name":"Test 4","stdin":"","expect":"","hidden":true,"events":["click Button \"Stations\"","click Button \"Help\"","click Button \"Help\""],"window":{"windows":[{"title":"City bikes","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Prices","onAction":true},{"n":4,"type":"Button","text":"Stations","onAction":true},{"n":5,"type":"Button","text":"Help","disable":true,"onAction":true}]},"center":{"n":6,"type":"Label","text":"A bike is broken? Leave it at a station and press its red button."}}}}],"problems":[]},"outline":"Window \"City bikes\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Prices\"\n      Button \"Stations\"\n      Button \"Help\" (disabled)\n    center: Label \"A bike is broken? Leave it at a station and press its red button.\""},{"name":"Test 5","stdin":"","expect":"","hidden":true,"events":["click Button \"Prices\"","click Button \"Help\"","click Button \"Stations\""],"window":{"windows":[{"title":"City bikes","scene":{"root":{"n":1,"type":"BorderPane","top":{"n":2,"type":"HBox","padding":[10,10,10,10],"spacing":10,"children":[{"n":3,"type":"Button","text":"Prices","onAction":true},{"n":4,"type":"Button","text":"Stations","disable":true,"onAction":true},{"n":5,"type":"Button","text":"Help","onAction":true}]},"center":{"n":6,"type":"Label","text":"There are 42 stations around the city."}}}}],"problems":[]},"outline":"Window \"City bikes\"\n  BorderPane\n    top: HBox spacing 10, padding 10\n      Button \"Prices\"\n      Button \"Stations\" (disabled)\n      Button \"Help\"\n    center: Label \"There are 42 stations around the city.\""}],"require":[],"forbid":[]},{"task":"A guide with two pages and a `Next` button that switches between them. The program clicks the button itself with `fire()`, and `getParent()` returns the pane a node is in, or `null` when it isn't in one. What does it print?\n","kind":"predict","seed":"import javafx.application.Application;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label hall = new Label(\"Great hall\");\n        Label tower = new Label(\"Tower\");\n        Button next = new Button(\"Next\");\n        BorderPane frame = new BorderPane(hall);\n        frame.setTop(next);\n        next.setOnAction(event -> {\n            if (frame.getCenter() == hall) {\n                frame.setCenter(tower);\n            } else {\n                frame.setCenter(hall);\n            }\n        });\n\n        next.fire();\n        System.out.println(frame.getCenter() == tower);\n        System.out.println(frame.getChildren().size() + \" \" + (hall.getParent() == null));\n        next.fire();\n        next.fire();\n        System.out.println(frame.getCenter() == hall);\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Guide\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","solution":"import javafx.application.Application;\nimport javafx.scene.Scene;\nimport javafx.scene.control.Button;\nimport javafx.scene.control.Label;\nimport javafx.scene.layout.BorderPane;\nimport javafx.stage.Stage;\n\npublic class Main extends Application {\n\n    @Override\n    public void start(Stage stage) {\n        Label hall = new Label(\"Great hall\");\n        Label tower = new Label(\"Tower\");\n        Button next = new Button(\"Next\");\n        BorderPane frame = new BorderPane(hall);\n        frame.setTop(next);\n        next.setOnAction(event -> {\n            if (frame.getCenter() == hall) {\n                frame.setCenter(tower);\n            } else {\n                frame.setCenter(hall);\n            }\n        });\n\n        next.fire();\n        System.out.println(frame.getCenter() == tower);\n        System.out.println(frame.getChildren().size() + \" \" + (hall.getParent() == null));\n        next.fire();\n        next.fire();\n        System.out.println(frame.getCenter() == hall);\n\n        stage.setScene(new Scene(frame));\n        stage.setTitle(\"Guide\");\n        stage.show();\n    }\n\n    public static void main(String[] args) {\n        launch(Main.class);\n    }\n}\n","hints":["`new BorderPane(hall)` puts `hall` in the center. Each `fire()` swaps the center: hall, then tower, then hall, then tower.","The BorderPane's children are the nodes in its regions: the button on top and the page in the center. The page that was taken out isn't in the pane any more, so it has no parent."],"tests":[{"name":"Output","stdin":"","expect":"true\n2 true\nfalse","hidden":false}],"require":[],"forbid":[],"lines":["true","2 true","false"]}]}