五子棋总结
五子棋V1
利用void java.awt.Graphics.drawLine(int x1, int y1, int x2, int y2)函数画棋盘
Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.
利用void java.awt.Graphics.fillOval(int x, int y, int width, int height)函数画棋子
Fills an oval bounded by the specified rectangle with the current color.
其中(x,y)是圆的正接矩形左上点。
缺陷:画棋子时会造成闪屏等现象。
五子棋V2
利用图片作为棋子和棋盘。
BufferedImage image = null;try {image = ImageIO.read(new File("E:/ve_eclipse/workspace/fivechess/src/image/chesstable1.jpg"));} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}g.drawImage(image, 0, 50, this);
jBut4.addActionListener(new ActionListener(){/* (non-Javadoc) * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubclearchesses();blnstate = false;javax.swing.SwingUtilities.updateComponentTreeUI(fcUI);}});
if(!blnstate){noderepaint(g);//根据nodelist重绘}myrepaint(g);//根据chesses[][]重绘
//根据落子顺序nodelist重绘private void noderepaint(Graphics g){for(int i = 0; i< nodeList.size(); i++){Node node = nodeList.get(i);chesses[node.getX()][node.getY()] = node.getColor();myrepaint(g);try {Thread.sleep(1000);} catch (InterruptedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}