GUI( JavaFX Scene Builder )/Lambda
Lambda_Event(2)
by pms93
2022. 8. 19.
package events;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class EventEx4 extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// padding을 이용해서 버튼클릭에 현실감을 더할 수 있다.
ImageView iv1 = new ImageView("/img/a.jpg"), iv2 = new ImageView("/img/images.jpg");
Button bt1 = new Button(), bt2 = new Button();
// bt1.setPrefSize(50, 50); bt2.setPrefSize(50, 50);
bt1.setGraphic(iv1); bt2.setGraphic(iv2);
bt1.setStyle("-fx-padding : 10 10 10 10"); bt2.setStyle("-fx-padding : 10 10 10 10");
bt1.setOnMousePressed(e -> {
bt1.setStyle("-fx-padding : 15 10 10 10");
});
bt1.setOnMouseReleased(e -> {
bt1.setStyle("-fx-padding : 10 10 10 10");
});
bt2.setOnMousePressed(e -> {
bt2.setStyle("-fx-padding : 15 10 10 10");
});
bt2.setOnMouseReleased(e -> {
bt2.setStyle("-fx-padding : 10 10 10 10");
});
HBox hbox = new HBox(40);
hbox.getChildren().addAll(bt1, bt2);
hbox.setAlignment(Pos.CENTER);
primaryStage.setScene(new Scene(hbox, 600, 600));
primaryStage.show();
}
}