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  
 47    /**
 48     * The main method is only needed for the IDE with limited
 49     * JavaFX support. Not needed for running from the command line.
 50     */
 51    public static void main(String[] args) {
 52      launch(args);
 53    }
 54  }