public void paintComponent(Graphics g)
{
super.paintComponent(g); g.drawString("Today is:" + Integer.toString(gc.get(GregorianCalendar.MONTH)) + "月"
+ Integer.toString(gc.get(GregorianCalendar.DATE)) + "日",  30, 30); for(int i = 0; i < 30; i++)
for( int k = 0; k < 30; k++)
isChessColor[i][k] = 0; drawChessColor = BLACKCHESS; for(int x = 0; x < 1000; x += 50)
g.drawLine(x,0,x,1000);
for(int y = 0; y < 1000; y += 50)
g.drawLine(0,y,1000,y);
}//===========================================================================================================
public void checkWin()
{
win = 0;
Point p = new Point(0,0);
Font f = new Font("Serif",Font.BOLD,40);
Graphics g = getGraphics();
g.setColor(Color.blue);
g.setFont(f); //检查垂直的。
for(int i1 = 0, k1 = currentChessLocation.x; i1 < 20; i1++)
{
s = Integer.toString(count);
if(win == 5)
{
if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 2)
{
g.drawString("白赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
}
else if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 1)
{
g.drawString("黑赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
}
acceptChess = false; regret.setEnabled(false);
start.setEnabled(true);
end.setEnabled(false);
break;
} else if(isChessColor[k1][i1] == isChessColor[currentChessLocation.x][currentChessLocation.y])
win++;
else
win = 0;
} //检查横向的。
for(int i2 = 0, k2 = currentChessLocation.y; i2 < 20; i2++)
{
s = Integer.toString(count);//提示总共下了多少步。
if(win == 5)
{
if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 2)
{
g.drawString("白赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
}
else if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 1)
{
g.drawString("黑赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
} acceptChess = false; regret.setEnabled(false);
start.setEnabled(true);
end.setEnabled(false);
break;
} else if(isChessColor[i2][k2] == isChessColor[currentChessLocation.x][currentChessLocation.y])
win++;
else
win = 0;
}
//检查左斜向上的。
for(int i3 = 0, k3 = currentChessLocation.y +currentChessLocation. x; i3 <= currentChessLocation.y + currentChessLocation.x && k3 >= 0; i3++,k3--)
{
s = Integer.toString(count);
if(win == 5)
{
if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 2)
{
g.drawString("白赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
}
else if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 1)
{
g.drawString("总共下了" + s + "步",600,550);
g.drawString("黑赢 !",600,600);
} acceptChess = false; regret.setEnabled(false);
start.setEnabled(true);
end.setEnabled(false);
break;
}
else if(isChessColor[k3][i3] == isChessColor[currentChessLocation.x][currentChessLocation.y])
win++;
else
win = 0;
}
//检查右斜向下的 for(int i4 = 29, k4 = currentChessLocation.y + 29 - currentChessLocation.x; i4 >= 0 && k4 >= 0; i4--,k4--)
{
s = Integer.toString(count);
if(win == 5)
{
if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 2)
{
g.drawString("白赢 !",600,600);
g.drawString("总共下了" + s + "步",600,550);
}
else if(isChessColor[currentChessLocation.x][currentChessLocation.y] == 1)
{
g.drawString("总共下了" + s + "步",600,550);
g.drawString("黑赢 !",600,600);
} acceptChess = false; regret.setEnabled(false);
start.setEnabled(true);
end.setEnabled(false);
break;
}
else if(isChessColor[i4][k4] == isChessColor[currentChessLocation.x][currentChessLocation.y])
win++;
else
win = 0;
} g.dispose();
}//===========================================================================================================
public void changeData(Point p)
{
if(p.x % 50 > 25)
{
currentChessPoint.x = mouseClickPoint.x - mouseClickPoint.x % 50 + 50;
}
else
{
currentChessPoint.x = mouseClickPoint.x - mouseClickPoint.x % 50;
} if(p.y % 50 > 25)
{
currentChessPoint.y = mouseClickPoint.y - mouseClickPoint.y % 50 + 50;
}
else
{
currentChessPoint.y = mouseClickPoint.y - mouseClickPoint.y % 50;
} currentChessLocation.x = currentChessPoint.x / 50;
currentChessLocation.y = currentChessPoint.y / 50;
}//===========================================================================================================
public void drawChess(Point p)
{
Graphics g = getGraphics();
//g.setColor(c);
if(acceptChess && drawChessColor == BLACKCHESS && isChessColor[currentChessLocation.x][currentChessLocation.y] == 0)
{
g.setColor(Color.black);
g.fillOval(p.x - 25, p.y - 25, 50, 50);
drawChessColor =  WHITECHESS;
isChessColor[currentChessLocation.x][currentChessLocation.y] = 1;
}
else if(acceptChess && drawChessColor == WHITECHESS && isChessColor[currentChessLocation.x][currentChessLocation.y] == 0)
{
g.setColor(Color.white);
g.fillOval(p.x - 25, p.y - 25, 50, 50);
drawChessColor =  BLACKCHESS;
isChessColor[currentChessLocation.x][currentChessLocation.y] = 2;
}
regret.setEnabled(true);
count++;
}
}//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
class MyFrame extends JFrame implements ComponentListener
{
private int frameWidth;//窗口尺寸。
private int frameHeight; public MyFrame()
{
Toolkit t = Toolkit.getDefaultToolkit();
Dimension d = t.getScreenSize();
frameWidth = (int)d.getWidth();
frameHeight = (int)d.getHeight();
setBounds(0, 0, frameWidth, frameWidth);
setTitle("wuziqi"); Container content = getContentPane();
content.add(new MyPanel()); addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}); this.addComponentListener(this);
} //ComponentListener接口里面的4个方法。
public void componentResized(ComponentEvent ce)//不给窗口改变大小。
{
//this.getWidth()和 getHeight()是获得当前窗口的尺寸。
setBounds(0, 0, Math.max(frameWidth, this.getWidth()), Math.max(frameWidth, this.getHeight()));//窗口不能小于屏幕尺寸。
}
public void componentShown(ComponentEvent ce){}
public void componentMoved(ComponentEvent ce){}
public void componentHidden(ComponentEvent ce){}
}//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
public class Wuziqi
{
public static void main(String[] args)
{
JFrame jf = new MyFrame();
jf.setVisible(true);
}