package othello;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
public class pro extends Application {
Circle[][] maru=new Circle[9][9];
int[][] point=new int[9][9];
int s,sx;
int px,py;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
px=5;
py=5;
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
maru[s][sx]=new Circle();
maru[s][sx].setLayoutX(50*s);
maru[s][sx].setLayoutY(50*sx);
maru[s][sx].setRadius(25);
maru[s][sx].setFill(Color.BLACK);
}
}
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
point[s][sx]=0;
}
}
Button btn1 = new Button();
btn1.setText("左");
btn1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(point[px][py]<50) maru[px][py].setFill(Color.BLACK);
px=px-1;
if(px<1)px=1;
maru[px][py].setFill(Color.WHITE);
}
});
btn1.setLayoutX(150);
btn1.setLayoutY(650);
Button btn2 = new Button();
btn2.setText("上");
btn2.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(point[px][py]<50)maru[px][py].setFill(Color.BLACK);
py=py+1;
if(py>8)py=8;
maru[px][py].setFill(Color.WHITE);
}
});
btn2.setLayoutX(200);
btn2.setLayoutY(650);
Button btn3 = new Button();
btn3.setText("決定");
btn3.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
maru[px][py].setFill(Color.RED);
point[px][py]=100;
}
});
btn3.setLayoutX(250);
btn3.setLayoutY(650);
Button btn4 = new Button();
btn4.setText("下");
btn4.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(point[px][py]<50)maru[px][py].setFill(Color.BLACK);
py=py-1;
if(py<1)py=1;
maru[px][py].setFill(Color.WHITE);
}
});
btn4.setLayoutX(300);
btn4.setLayoutY(650);
Button btn5 = new Button();
btn5.setText("右");
btn5.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(point[px][py]<50) maru[px][py].setFill(Color.BLACK);
px=px+1;
if(py>8)px=8;
maru[px][py].setFill(Color.WHITE);
}
});
btn5.setLayoutX(350);
btn5.setLayoutY(650);
Group root = new Group();
Scene scene = new Scene(root, 700, 700);
root.getChildren().add(btn1);
root.getChildren().add(btn2);
root.getChildren().add(btn3);
root.getChildren().add(btn4);
root.getChildren().add(btn5);
for(s=1;s<9;s++){
for(sx=1;sx<9;sx++){
root.getChildren().add(maru[s][sx]);
}
}
primaryStage.setTitle("Button");
primaryStage.setScene(scene);
primaryStage.show();
}
}
最終更新:2013年09月04日 00:59