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