Java Code Examples for javafx.scene.shape.Rectangle#setOnMouseClicked()

The following examples show how to use javafx.scene.shape.Rectangle#setOnMouseClicked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeaBattle.java    From games_oop_javafx with Apache License 2.0 6 votes vote down vote up
private void buildShip(Group board, int desk, int startX, int startY) {
    Rectangle rect = new Rectangle();
    rect.setX(startX);
    rect.setY(startY);
    rect.setHeight(25);
    rect.setWidth(desk * 25);
    rect.setFill(Color.BLACK);
    rect.setOnMouseDragged(
            event -> {
                rect.setX(event.getX());
                rect.setY(event.getY());
            }
    );
    rect.setOnMouseReleased(
            event -> {
                rect.setX((((int) event.getX() / 25) * 25));
                rect.setY(((int) event.getY() / 25) * 25);
            }
    );
    rect.setOnMouseClicked(
            event -> {
                if (event.getButton() != MouseButton.PRIMARY) {
                    Rectangle momento = new Rectangle(rect.getX(),
                            rect.getY(), rect.getWidth(), rect.getHeight());
                    rect.setWidth(momento.getHeight());
                    rect.setHeight(momento.getWidth());
                }
            }
    );
    board.getChildren().add(rect);
}
 
Example 2
Source File: Connect4App.java    From FXTutorials with MIT License 6 votes vote down vote up
private List<Rectangle> makeColumns() {
    List<Rectangle> list = new ArrayList<>();

    for (int x = 0; x < COLUMNS; x++) {
        Rectangle rect = new Rectangle(TILE_SIZE, (ROWS + 1) * TILE_SIZE);
        rect.setTranslateX(x * (TILE_SIZE + 5) + TILE_SIZE / 4);
        rect.setFill(Color.TRANSPARENT);

        rect.setOnMouseEntered(e -> rect.setFill(Color.rgb(200, 200, 50, 0.3)));
        rect.setOnMouseExited(e -> rect.setFill(Color.TRANSPARENT));

        final int column = x;
        rect.setOnMouseClicked(e -> placeDisc(new Disc(redMove), column));

        list.add(rect);
    }

    return list;
}
 
Example 3
Source File: JavaFXDisplayDriver.java    From game-of-life-java with MIT License 5 votes vote down vote up
private void attachListeners(Rectangle r, Cell c) {
    r.setOnMousePressed(e -> { r.setFill(Color.GRAY); });

    r.setOnMouseClicked(e -> {
        r.setFill(c.getState() ? Color.WHITE : Color.STEELBLUE);
        c.setNewState(!c.getState());
        c.updateState();
    });
}
 
Example 4
Source File: VertexGraphLabelsEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
LabelEntry(final List<LabelEntry> host, final Pane visualHost, final String attributeName, final ConstellationColor color, final float size) {

                attrCombo = new ComboBox<>(FXCollections.observableList(attributeNames));
                attrCombo.setPrefWidth(150);
                attrCombo.getSelectionModel().select(attributeName);
                attrCombo.getSelectionModel().selectedItemProperty().addListener((o, n, v) -> {
                    update();
                });

                colorRect = new Rectangle(20, 20);
                this.color = color.getJavaFXColor();
                colorRect.setFill(this.color);
                colorRect.setStroke(Color.LIGHTGREY);
                colorRect.setOnMouseClicked(getChooseColorEventHandler());

                sizeText = new TextField(String.valueOf(size));
                sizeText.setPrefWidth(50);
                sizeText.textProperty().addListener((o, n, v) -> {
                    update();
                });

                final Button upButton = new Button("", new ImageView(UserInterfaceIconProvider.CHEVRON_UP.buildImage(16)));
                upButton.setOnAction(e -> {
                    moveUp();
                    update();
                });
                final Button downButton = new Button("", new ImageView(UserInterfaceIconProvider.CHEVRON_DOWN.buildImage(16)));
                downButton.setOnAction(e -> {
                    moveDown();
                    update();
                });
                final Button removeButton = new Button("", new ImageView(UserInterfaceIconProvider.CROSS.buildImage(16)));
                removeButton.setOnAction(e -> {
                    remove();
                    update();
                });

                entry = new HBox(10);
                entry.getChildren().addAll(attrCombo, colorRect, sizeText, upButton, downButton, removeButton);

                this.host = host;
                this.host.add(this);
                this.visualHost = visualHost;
                this.visualHost.getChildren().add(entry);
            }
 
Example 5
Source File: TransactionGraphLabelsEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
LabelEntry(final List<LabelEntry> host, final Pane visualHost, final String attributeName, final ConstellationColor color, final float size) {
    attrCombo = new ComboBox<>(FXCollections.observableList(attributeNames));
    attrCombo.setPrefWidth(150);
    attrCombo.getSelectionModel().select(attributeName);
    attrCombo.getSelectionModel().selectedItemProperty().addListener((o, n, v) -> {
        update();
    });

    colorRect = new Rectangle(20, 20);
    this.color = color.getJavaFXColor();
    colorRect.setFill(this.color);
    colorRect.setStroke(Color.LIGHTGREY);
    colorRect.setOnMouseClicked(getChooseColorEventHandler());

    sizeText = new TextField(String.valueOf(size));
    sizeText.setPrefWidth(50);
    sizeText.textProperty().addListener((o, n, v) -> {
        update();
    });

    final Button upButton = new Button("", new ImageView(UserInterfaceIconProvider.CHEVRON_UP.buildImage(16)));
    upButton.setOnAction(e -> {
        moveUp();
        update();
    });
    final Button downButton = new Button("", new ImageView(UserInterfaceIconProvider.CHEVRON_DOWN.buildImage(16)));
    downButton.setOnAction(e -> {
        moveDown();
        update();
    });
    final Button removeButton = new Button("", new ImageView(UserInterfaceIconProvider.CROSS.buildImage(16)));
    removeButton.setOnAction(e -> {
        remove();
        update();
    });

    entry = new HBox(10);
    entry.getChildren().addAll(attrCombo, colorRect, sizeText, upButton, downButton, removeButton);

    this.host = host;
    this.host.add(this);
    this.visualHost = visualHost;
    this.visualHost.getChildren().add(entry);
}