アットウィキロゴ

9876

package don;
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.shape.*;
import javafx.animation.AnimationTimer;
import javafx.scene.paint.Color;
 
 
public class pro extends Application {
 
 
    Rectangle pm;
    int time,px,py;
 
public static void main(String[] args) {
launch(args);
}
 
 
@Override
public void start(Stage primaryStage) {
 
Group root = new Group();
Scene scene = new Scene(root, 700, 700); 
 
time=0;
 
px=250;
py=250;
 
pm=new Rectangle(50,50,Color.RED);
pm.setLayoutX(50+50*px);
pm.setLayoutY(50+50*py);
 
root.getChildren().add(pm);
 
primaryStage.setTitle("Packman");
primaryStage.setScene(scene);
primaryStage.show();
 
 
new AnimationTimer() {
@Override
public void handle(long now) {
 
time=time+1;
 
if(time>10){
 
    double z;
   z=Math.random();
 
   if(z>0.5)px=px+10;
   if(z<0.5)px=px-10;
 
   z=Math.random();
 
   if(z>0.5)py=py+10;
   if(z<0.5)py=py-10;
 
 
pm.setLayoutX(50+px);
pm.setLayoutY(50+py);
 
time=0;
}
 
}
}.start();
 
} 
 
 
}
最終更新:2013年08月22日 12:25