package fx08;
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.shape.*;
import javafx.scene.paint.Color;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
public class pro extends Application {
int x=new int[9][9];
int s,sx;
Rectangle r=new Rectangle[10][10];
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++){
x[s][sx]=0;
}
}
x[4][4]=1;
x[5][5]=1;
x[4][5]=2;
x[5][4]=2;
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
r[s][sx]=new Rectangle(50,50);
r[s][sx].setLayoutX(50+50*sx);
r[s][sx].setLayoutY(50+50*s);
if(x[s][sx]==0)r[s][sx].setFill(Color.BLUE);
if(x[s][sx]==1)r[s][sx].setFill(Color.BLACK);
if(x[s][sx]==2)r[s][sx].setFill(Color.WHITE);
}
}
Group root = new Group();
Scene scene = new Scene(root, 600, 600);
root.setOnMousePressed(new EventHandler() {
public void handle(MouseEvent me) {
double x1,y1;
int s1,s2;
x1=me.getX();
y1=me.getY();
s1=(int)y1/50-1;
s2=(int)x1/50-1;
if(s1<1)s1=1;
if(s1>8)s1=8;
if(s2<1)s2=1;
if(s2>8)s2=8;
change(s1,s2);
draw();
}
});
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
root.getChildren().add(r[s][sx]);
}
}
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
void draw(){
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
if(x[s][sx]==0)r[s][sx].setFill(Color.BLUE);
if(x[s][sx]==1)r[s][sx].setFill(Color.BLACK);
if(x[s][sx]==2)r[s][sx].setFill(Color.WHITE);
}
}
}
void change(int s1,int s2){
x[s1][s2]=1;
}
}