编程语言
首页 > 编程语言> > Java 五子棋(一绘)制棋盘、棋子

Java 五子棋(一绘)制棋盘、棋子

作者:互联网

五子棋

界面

网格

棋子

Code

public void showUI(){
        JFrame jf=this;
        jf.setTitle("五子棋");
        jf.setSize(800,800);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        jf.setVisible(true);
public void paint(Graphics graphics){
        super.paint(graphics);
        for(int i=0;i<11;i++) {
            graphics.drawLine(StudentIface.x, StudentIface.y+i*StudentIface.SIZE,StudentIface.x+StudentIface.SIZE*StudentIface.L, StudentIface.y+i*StudentIface.SIZE);
            graphics.drawLine(StudentIface.x+i*StudentIface.SIZE, StudentIface.y+StudentIface.SIZE*StudentIface.R,StudentIface.x+i*StudentIface.SIZE,StudentIface.y);
        }
        System.out.println("画笔");
    }
public interface StudentIface {
  public   int x=100;
  public   int y=100;
  public   int L=10;
  public   int R=10;
   public int SIZE=40;
}
public class StudentLisenter implements MouseListener {
    Graphics graphics;

    public void setGraphics(Graphics graphics){
        this.graphics=graphics;
        System.out.println(graphics+"g");
    }
public void mousePressed(MouseEvent e) {
        int x = e.getX();
        int y = e.getY();
        count++;
        for (int i = 0; i < SIZE; i++) {
            if (count % 2 == 1) {
                graphics.setColor(Color.BLACK);
                graphics.fillOval(x, y, 20, 20);
            } else {
                graphics.setColor(Color.WHITE);
                graphics.fillOval(x, y, 20, 20);
            }
        }
    }
 Graphics g=jf.getGraphics();
        StudentLisenter studentLisenter=new StudentLisenter();
        jf.addMouseListener(studentLisenter);
        studentLisenter.setGraphics(g);

标签:JFrame,Java,int,五子棋,监听器,graphics,jf,一绘,public
来源: https://blog.csdn.net/yxiulian/article/details/121328485