java棋盘覆盖图形化界面_棋盘覆盖问题简单动画演示JAVA

该博客展示了如何使用Java编程实现棋盘覆盖问题的简单动画演示。通过定义棋盘大小、绘制函数以及处理棋盘四个角落的特殊情况,动态展示棋盘覆盖过程。主要涉及图形化界面和多线程技术。
摘要由CSDN通过智能技术生成

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);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值