Simple GIS

GISプログラムの練習

オセロ

package othx;

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.scene.paint.Color;
import javafx.scene.input.MouseEvent;

public class pro extends Application {
    
    Rectangle rec=new Rectangle[9][9];
    int s,sx;
    
    public static void main(String[] args) {
        launch(args);
    }
    
    
    
    @Override
    public void start(Stage primaryStage) {
       
       
        for(s=1;s<9;s++){
        for(sx=1;sx<9;sx++){
        rec[s][sx]=new Rectangle(50*s,50*sx,50,50);
        rec[s][sx].setFill(Color.GREEN);
        }
        }
        
        Group root = new Group();
        Scene scene = new Scene(root, 700, 700);
        
        
        
        for(s=1;s<9;s++){
        for(sx=1;sx<9;sx++){
         root.getChildren().add(rec[s][sx]);   
        }    
        }
    
        
root.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() {
@Override
public void handle(MouseEvent me) {
double mx,my;
int cx,cy,h;
mx=me.getX();
my=me.getY();

cx=(int)(mx/50);
cy=(int)(my/50);
if(cx>8)cx=8;
if(cx<1)cx=1;
if(cy>8)cy=8;
if(cy<1)cy=1;

 rec[cx][cy].setFill(Color.BLACK);


}
});
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    
}