0
Block
のグリッド6X6要素を作成するプロジェクトを作成しました。 Block
をクリックすると、オレンジ色の円が表示されます。問題は、ボタンをクリックすると、1秒ごとにランダムに右、左、上、下に移動する各円が表示されます。 1つのサークルが上がったように、次に左に行くと、それは再び上に行く。オブジェクトごとに異なるアニメーションを開始する方法JavaFX
class Block extends StackPane {
Rectangle rect = new Rectangle(40, 40);
Circle circ = new Circle(20);
EventHandler a = new EventHandler() {
public void handle(Event t) {
circ.setVisible(true);
}
};
Block() {
rect.setFill(Paint.valueOf("WHITE"));
rect.setStroke(Paint.valueOf("BLACK"));
rect.setOnMouseClicked(a);
circ.setFill(Paint.valueOf("ORANGE"));
circ.setVisible(false);
this.getChildren().addAll(rect, circ);
}
}
public class JavaFXApplication8 extends Application {
@Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
Block[][] matrice = new Block[6][6];
for (int i = 0; i < 6; i++) {
matrice[i] = new Block[6];
for (int j = 0; j < 6; j++) {
matrice[i][j] = new Block();
root.add(matrice[i][j], j, i);
}
}
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
質問とは無関係: 'Paint.valueOf(" ORANGE ")'の代わりに 'Color.ORANGE'を使用してください。 ( 'Color extends Paint')。 – fabian
http://blog.netopyr.com/2012/06/14/using-the-javafx-animationtimer/をご覧ください – GOXR3PLUS