📄 ticboard.java
字号:
import java.awt.*;
import javax.swing.JPanel;
public class TicBoard extends JPanel
{ public TicBoard(Image o,Image x,Color bg,TicTacToe TTT)
{ this.x=x;this.o=o;
setBackground(bg);
Tic=TTT;
}
public void setGame(TicGame g) {game=g;}
public void paintComponent(Graphics g)
{ this.g=g;
super.paintComponent(g);
size(getWidth(),getHeight());
g.setColor(Color.black);
drawBoard();
game.draw(); /*call drawPiece*/
}
protected void drawBoard()
{ g.drawLine(tw,y0,tw,height);
g.drawLine(2*tw+lw,y0,2*tw+lw,height);
g.drawLine(x0,th,width,th);
g.drawLine(x0,2*th+lw,width,2*th+lw);
}
public void size(int w,int h)
{ width=w;height=h;
tw=(width-2*lw)/3;
th=(height-2*lw)/3;
}
public void drawPiece(boolean player,int i)
{ int r=i/3,c=i%3;
g.drawImage((player==TicGame.PLAYER_X)?x:o,c*(tw+lw)+1,r*(th+lw)+1,tw-1,th-1,this);
}
public int col(int x) { return (x*3)/width;}
public int row(int y) { return (y*3)/height;}
protected TicGame game;
protected TicTacToe Tic;
protected Graphics g;
protected Image x,o;
protected int x0=0,y0=0;
protected int width,height;
protected int tw,th;
protected int lw=1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -