Problem

Why is the getPane() method protected in Listing 1? Why is the data field text protected?L...

Why is the getPane() method protected in Listing 1? Why is the data field text protected?

LISTING 1 ButtonDemo.java

1 import javafx.application.Application;

2 import javafx.stage.Stage;

3 import javafx.geometry.Pos;

4 import javafx.scene.Scene;

5 import javafx.scene.control.Button;

6 import javafx.scene.image.ImageView;

7 import javafx.scene.layout.BorderPane;

8 import javafx.scene.layout.HBox;

9 import javafx.scene.layout.Pane;

10 import javafx.scene.text.Text;

11

12 public class ButtonDemo extends Application {

13 protected Text text = new Text(50, 50, "JavaFX Programming");

14

15 protected BorderPane getPane() {

16 HBox paneForButtons = new HBox(20);

17 Button btLeft = new Button("Left",

18 new ImageView("image/left.gif"));

19 Button btRight = new Button("Right",

20 new ImageView("image/right.gif"));

21 paneForButtons.getChildren().addAll(btLeft, btRight);

22 paneForButtons.setAlignment(Pos.CENTER);

23 paneForButtons.setStyle("-fx-border-color: green");

24

25 BorderPane pane = new BorderPane();

26 pane.setBottom(paneForButtons);

27

28 Pane paneForText = new Pane();

29 paneForText.getChildren().add(text);

30 pane.setCenter(paneForText);

31

32 btLeft.setOnAction(e -> text.setX(text.getX() - 10));

33 btRight.setOnAction(e -> text.setX(text.getX() + 10));

34

35 return pane;

36 }

37

38 @Override // Override the start method in the Application class

39 public void start(Stage primaryStage) {

40 // Create a scene and place it in the stage

41 Scene scene = new Scene(getPane(), 450, 200);

42 primaryStage.setTitle("ButtonDemo"); // Set the stage title

43 primaryStage.setScene(scene); // Place the scene in the stage

44 primaryStage.show(); // Display the stage

45 }

46 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT