public classChessBroad {private static int SIZE = 8;private static String arr[][] = newString[SIZE][SIZE];private staticTable table;static{for (int i = 0; i < SIZE; i++) {for (int j = 0; j < SIZE; j++) {
arr[i][j]= "0";
}
}
table=newTable(arr);
}private static voiddraw() {try{
Thread.sleep(100);
table.jTable.validate();
table.jTable.updateUI();
}catch(InterruptedException e) {
e.printStackTrace();
}for (int i = 0; i < SIZE; i++) {for (int j = 0; j < SIZE; j++) {
System.out.print(arr[i][j]+ " ");
}
System.out.println();
}
System.out.println("--------------");
}/***@paramb_x the abscissa at the top left
*@paramb_y the top left ordinate
*@paramp_x the abscissa of the particular location
*@paramp_y the ordinate of the particular location
*@paramsize the SIZE of the broad*/
private static void broad(int b_x, int b_y, int p_x, int p_y, intsize) {
draw();if (size == 1) return;int temp_size = size / 2;if (p_x < b_x + temp_size && p_y < b_y + temp_size) {//特殊点在左上角
broad(b_x, b_y, p_x, p_y, size / 2);
B(b_x, b_y, temp_size,"a");
C(b_x, b_y, temp_size,"a");
D(b_x, b_y, temp_size,"a");
}else if (p_x >= b_x + temp_size && p_y < b_y + temp_size) {//特殊点在左下角
broad(b_x + temp_size, b_y, p_x, p_y, size / 2);
A(b_x, b_y, temp_size,"b");
C(b_x, b_y, temp_size,"b");
D(b_x, b_y, temp_size,"b");
}else if (p_x < b_x + temp_size && p_y >= b_y + temp_size) {//特殊点在右上角
broad(b_x, b_y + temp_size, p_x, p_y, size / 2);
A(b_x, b_y, temp_size,"c");
B(b_x, b_y, temp_size,"c");
D(b_x, b_y, temp_size,"c");
}else {//特殊点在右下角
broad(b_x + temp_size, b_y + temp_size, p_x, p_y, size / 2);
A(b_x, b_y, temp_size,"d");
B(b_x, b_y, temp_size,"d");
C(b_x, b_y, temp_size,"d");
}
}private static void A(int b_x, int b_y, int size, String symbol) {//左上角
arr[b_x+ size - 1][b_y + size - 1] = symbol;//左上角
broad(b_x, b_y, b_x + size - 1, b_y + size - 1, size);//左上角
}private static void B(int b_x, int b_y, int size, String symbol) {//左下角
arr[b_x+ size][b_y + size - 1] = symbol;//左下角
broad(b_x + size, b_y, b_x + size, b_y + size - 1, size);//左下角
}private static void C(int b_x, int b_y, int size, String symbol) {//右上角
arr[b_x+ size - 1][b_y + size] = symbol;//右上角
broad(b_x, b_y + size, b_x + size - 1, b_y + size, size);//右上角
}private static void D(int b_x, int b_y, int size, String symbol) {//右下角
arr[b_x + size][b_y + size] = symbol;//右下角
broad(b_x + size, b_y + size, b_x + size, b_y + size, size);//右下角
}public static voidmain(String[] args) {
broad(0, 0, 2, 3, SIZE);
draw();
Table table= newTable(arr);
table.setVisible(true);
}
}