小弟第一次发帖
package WuZiQi;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class WuZiQi extends JFrame{
public WuZiQi(){
add(new WuZiQiPanel());
}

public static void main(String [] args){
JFrame frame = new WuZiQi();
frame.setTitle("WuZiQi");
frame.setSize(600,600);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

class WuZiQiPanel extends JPanel{
private int x = 0;
private int y = 0;
private boolean isBlack;
int[][] chess = new int[20][20];//存放旗子的数组。
public WuZiQiPanel(){
isBlack = true;
//初始化棋盘。
for(int i = 0;i<20;i++){
for(int j = 0;j<20;j++){
chess[i][j] = 0;
}
}
addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
x = e.getX();//判断旗子的位置。
if(x%30>15){
x = x - x%30 + 20;
}
else{
x = x - x%30 - 10;
}

y = e.getY();
if(y%30>15){
y = y - y%30 + 20;
}
else{
y = y - y%30 - 10;
}

if(isBlack == true){
chess[x/30-1][y/30-1] = 1;
isBlack = false;
repaint();
}
if(isBlack == false){
chess[x/30-1][y/30-1] = 2;
isBlack = true;
repaint();
}
}
});
}

protected void paintComponent(Graphics g){
super.paintComponent(g);
for(int i = 1;i<=20;i++){
g.drawLine(0,i*30,600,i*30);
}
for(int i = 1;i<=20;i++){
g.drawLine(i*30,0,i*30,600);
}

for(int i = 0;i<20;i++){
for(int j = 0;j<20;j++){
if(chess[i][j] == 1){
g.setColor(Color.black);
g.fillOval(x,y,20,20);
}
if(chess[i][j] == 2){
g.setColor(Color.white);
g.fillOval(x,y,20,20);
}
}
}
}
}}