/**
* @author foas@bbs.xjtu.edu.cn on oct.23,2004 12:00 【程序编程相关:山外看山 —— 评The Art of 】 【推荐阅读:Regsvr32 用法和错误消息的说明】 * 【扩展信息:免费网盘】 * todo to change the template for this generated type comment go to window - * preferences - java - code generation - code and comments */
import java.awt.*;
import java.awt.event.*;import javax.swing.*;
public class first extends jframe {
public first() {
drawpane drawpane = new drawpane(getbackground()); container pane = getcontentpane(); pane.add(drawpane, borderlayout.center); setsize(600, 580); //f.setextendedstate(jframe.maximized_both); //f.setundecorated(true); //f.setalwaysontop(true); //f.setlocationbyplatform(true);setlocation(208, 104);
setdefaultcloseoperation(jframe.exit_on_close); //setbackground(color.pink); setresizable(false); setvisible(true); }public static void main(string[] args) {
new first(); } }class drawpane extends jpanel {
private insets insets;final static int black = -1;
final static int white = 1;
private point point = null;
private int colorstatus;
private int[][] status = null;
private int count;
private int chessnum;
private jtextarea infotext = null;
private int[][] statusw = null;
private int level=1 ;
private int whitecount=0;
private int blackcount=0;
private color bgcolor=null; public drawpane(color c) {initcomponent();
initchess(); bgcolor=c; addmouselistener(new mouseadapter() { public void mouseclicked(mouseevent e) { response(e.getpoint()); } }); setfocusable(true); addkeylistener(new mykeylistener()); }public void paintcomponent(graphics g) {
super.paintcomponent(g); if (insets == null) { insets = getinsets(); } //super.paintcomponents(g); graphics2d g2d = (graphics2d) g; g2d.setcolor(color.orange); g2d.fill3drect(50, 50, 400, 400, true); g2d.setcolor(color.red); for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { g2d.drawstring(i + "", 50 * i + 75, 45); g2d.drawstring(j + "", 40, 50 * j + 75); g2d.drawrect(50 + 50 * i, 50 + 50 * j, 50, 50); if (status[i][j] == black) { g2d.setcolor(color.black); g2d.filloval(i * 50 + 53, j * 50 + 53, 44, 44); } if (status[i][j] == white) { g2d.setcolor(color.white); g2d.filloval(i * 50 + 53, j * 50 + 53, 44, 44); } if (status[i][j] > 1) { // g2d.setcolor(color.blue); // g2d.drawstring("" + (status[i][j] - 1), i * 50 + 75, // j * 50 + 75); g2d.drawstring("x", i * 50 + 75, j * 50 + 75); }g2d.setcolor(color.black);
g2d.filloval(200, 470, 30, 30);g2d.setcolor(color.white);
g2d.filloval(300, 470, 30, 30);g2d.setcolor(bgcolor);
g2d.fillrect(240, 470, 60, 30); g2d.fillrect(340, 470, 60, 30); g2d.setcolor(color.red); g2d.drawstring("" + blackcount, 240, 490); g2d.drawstring("" + whitecount, 340, 490);}
} //jug(colorstatus); }public void initcomponent() {
infotext = new jtextarea(); ... 下一页