アットウィキロゴ

FXkll

package tennsi2;
 
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;
import javafx.scene.input.MouseEvent;
 
 
public class pro extends Application {
 
 
 
    Rectangle ball;
    int time,bx,by,dx,dy;
 
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;
 
int s,sx;
 
bx=25;
by=25;
dx=5;
dy=3;
 
 
ball=new Rectangle(50,50,Color.GREEN);
ball.setLayoutX(10*bx);
ball.setLayoutY(10*by);
root.getChildren().add(ball);
 
primaryStage.setTitle("練習");
primaryStage.setScene(scene);
primaryStage.show();
 
new AnimationTimer() {
@Override
public void handle(long now) {
 
time=time+1;
 
if(time>10){
 
   bx=bx+dx;
   by=by+dy;
 
   if(bx>50)dx=-dx;
   if(bx<0)dx=-dx;
 
   if(by>50)dy=-dy;
   if(by<0)dy=-dy;
 
   ball.setLayoutX(10*bx);
ball.setLayoutY(10*by);
 
time=0;
}
 
}
}.start();
 
 
 
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent me) {
double mx,my;
 
mx=me.getX();
my=me.getY();
 
int x1,y1;
 
ball.setFill(Color.RED);
 
 
 
}
}); 
 
} 
 
 
 
}
最終更新:2013年09月05日 14:27