0
我开始学习JavaFX。我制作了一个创建形状的简单程序。坐标位置的光标和颜色变化与一定条件 - JavaFX
我想要做驱动的执行方法基本事件,比如:
- 打印如果形状
- 内其改变颜色每次光标进入的形状,然后改变它的光标的坐标回到原来的一旦它出了形状
以下是我所做
import javafx.application.Application;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Polygon;
public class ColouredShapes extends Application {
@Override
public void start(Stage stage) {
int radius = 40;
int strokeWidth = 3;
Color strokeColor = Color.BROWN;
Circle circle1 = new Circle(250, 125, radius, Color.RED);
circle1.setStroke(strokeColor);
circle1.setStrokeWidth(strokeWidth);
Rectangle square = new Rectangle(375, 85, 80, 80);
square.setFill(Color.BLUE);
square.setStroke(strokeColor);
square.setStrokeWidth(strokeWidth);
Polygon polygon = new Polygon();
polygon.getPoints().addAll(new Double[]{
50.0, 85.0,
110.0, 60.0, 125.0, 175.0});
polygon.setFill(Color.YELLOWGREEN);
Group root = new Group();
root.getChildren().addAll(circle1, square, polygon);
Scene scene = new Scene(root, 500, 250, Color.LIGHTYELLOW);
stage.setScene(scene);
stage.show();
}
public static void maint(String[] args){
launch(args);
}
}
当你创建你的形状,创造的OnEnter和的OnExit处理。 – Sedrick
http://stackoverflow.com/questions/13359382/creating-a-mouselistner-to-javafx-rectangle。而不是onMouseClicked使用onMouseEntered和另一个OnMouseExited。 – Sedrick