这是我到目前为止所得到的
package photo.album;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
*
* enter code here
*/
public class PhotoAlbum extends Application {
Button btnTree, btnFwheel, btnAlley, btnFrog, btnPic, btnRemove;
ImageView imgpic;
HBox btnbox;
@Override
public void start(Stage primaryStage) {
btnTree = new Button("Palmetto Tree");
btnFwheel = new Button("Ferris Wheel");
btnAlley = new Button("Alley Way");
btnFrog = new Button("Little Frog");
btnPic = new Button("Picture");
btnRemove = new Button("Remove");
btnTree.setOnAction(e->handleButtonAction(e));
btnFwheel.setOnAction(e->handleButtonAction(e));
btnAlley.setOnAction(e->handleButtonAction(e));
btnFrog.setOnAction(e->handleButtonAction(e));
btnPic.setOnAction(e->handleButtonAction(e));
btnRemove.setOnAction(e->handleButtonAction(e));
//put top 5 buttons in a box
btnbox = new HBox(btnTree, btnFwheel, btnAlley, btnFrog, btnPic);
btnbox.setSpacing(10);
btnbox.setPadding(new Insets(20));
// make the image
imgpic = new ImageView();
//create the BorderPane
BorderPane root = new BorderPane();
root.setPadding(new Insets(10));
root.setTop(btnbox);
root.setCenter(imgpic);
root.setBottom(btnRemove);
//center the button in the bottom region
BorderPane.setAlignment(btnRemove, Pos.CENTER);
Scene scene = new Scene(root, 700, 800);
primaryStage.setTitle("Photo Album");
primaryStage.setScene(scene);
primaryStage.show();
}
private void handleButtonAction(ActionEvent event) {
Image img;
if(event.getSource() == btnTree)
img = new Image("file:///../image/Tree.jpg");
else if(event.getSource() == btnFwheel)
img = new Image("file:///../image/Fwheel.png");
else if(event.getSource() == btnAlley)
img = new Image("file:///../image/Alley.jpg");
else if(event.getSource() == btnFrog)
img = new Image("file:///../image/Frog.png");
else if(event.getSource() == btnPic)
img = new Image("file:///../image/Pic.jpg");
else
img = null;
imgpic.setImage(img);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
我似乎无法做到正确。我只是希望能够在点击它们时显示有关照片的说明。如果有人能带领我朝着正确的方向前进,我将非常感激。