Home » Java » java – how to show clickable circle instead of mouse cursor in javaFX?-Exceptionshub

java – how to show clickable circle instead of mouse cursor in javaFX?-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want to make a network based game in which are two players.

Players has 50px radius circles instead of cursors. The circles are appearing and dissapearing every few seconds for the short period of time. Players’s duty is to click the oponent circle to get the point.

Im using the Anchor pane as a game interface and i don’t know how to make the circles instead of cursors.

Thank you for all of your answers.

sample.fxml :

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="900.0" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <children>
        <GridPane gridLinesVisible="true" minHeight="100.0" minWidth="900.0" style="-fx-background-color: #CDE8C8; -fx-border-color: black;">
            <columnConstraints>
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
            </columnConstraints>
            <rowConstraints>
                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            </rowConstraints>
            <children>
                <Text fx:id="minuty" strokeType="OUTSIDE" strokeWidth="0.0" text="00" wrappingWidth="225.125">
                    <font>
                        <Font size="40.0" />
                    </font>
                    <GridPane.margin>
                        <Insets left="50.0" />
                    </GridPane.margin>
                </Text>
                <Text strokeType="OUTSIDE" strokeWidth="0.0" text=":" textAlignment="CENTER" wrappingWidth="224.671875">
                    <font>
                        <Font size="40.0" />
                    </font>
                </Text>
                <Text fx:id="sekundy" strokeType="OUTSIDE" strokeWidth="0.0" text="00" textAlignment="RIGHT" wrappingWidth="176.9375">
                    <font>
                        <Font size="40.0" />
                    </font>
                    <GridPane.margin>
                        <Insets />
                    </GridPane.margin>
                </Text>
                <Text fx:id="stavcerveny" fill="RED" strokeType="OUTSIDE" strokeWidth="0.0" text="0" wrappingWidth="208.5625" GridPane.columnIndex="1">
                    <font>
                        <Font size="40.0" />
                    </font>
                    <GridPane.margin>
                        <Insets left="50.0" />
                    </GridPane.margin>
                </Text>
                <Text strokeType="OUTSIDE" strokeWidth="0.0" text=":" textAlignment="CENTER" wrappingWidth="225.671875" GridPane.columnIndex="1">
                    <font>
                        <Font size="40.0" />
                    </font>
                </Text>
                <Text fx:id="stavmodry" fill="#0073ff" strokeType="OUTSIDE" strokeWidth="0.0" text="0" textAlignment="RIGHT" wrappingWidth="179.5625" GridPane.columnIndex="1">
                    <font>
                        <Font size="40.0" />
                    </font>
                </Text>
                <Button alignment="CENTER" mnemonicParsing="false" onMouseClicked="#zapnutie" prefHeight="25.0" prefWidth="226.0" text="PLAY" GridPane.columnIndex="2">
                    <GridPane.margin>
                        <Insets bottom="40.0" left="40.0" right="40.0" />
                    </GridPane.margin>
                </Button>
                <Button mnemonicParsing="false" onMouseClicked="#restart" prefHeight="25.0" prefWidth="227.0" text="RESTART" textAlignment="CENTER" GridPane.columnIndex="2">
                    <opaqueInsets>
                        <Insets />
                    </opaqueInsets>
                    <GridPane.margin>
                        <Insets left="40.0" right="40.0" top="50.0" />
                    </GridPane.margin>
                </Button>
                <Slider fx:id="obtiazne" prefHeight="14.0" prefWidth="126.0" GridPane.columnIndex="3">
                    <GridPane.margin>
                        <Insets left="20.0" right="20.0" />
                    </GridPane.margin>
                </Slider>
            </children>
        </GridPane>
      <AnchorPane fx:id="hra" layoutX="8.0" layoutY="100.0" prefHeight="500.0" prefWidth="900.0" />
    </children>
</AnchorPane>

There’s nothing in Controller.java or Main.java yet som i’m publishing only sample.fxml 🙂

How to&Answers: