⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gomokubutton.java

📁 基于Java的五子棋的源代码
💻 JAVA
字号:
package net.sourceforge.gomoku;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;public final class GomokuButton extends JButton {  private final Square square;  private static final ImageIcon computerIcon      = new ImageIcon(GomokuButton.class.getResource("images/ComputerPiece.png"));  private static final ImageIcon playerIcon      = new ImageIcon(GomokuButton.class.getResource("images/PlayerPiece.png"));  private static final ImageIcon noIcon      = new ImageIcon(GomokuButton.class.getResource("images/NoPiece.png"));  private static final Insets noMargin = new Insets(0, 0, 0, 0);  public GomokuButton(final Square square) {    this.square = square;    setIcon(noIcon);    setIconTextGap(0);    setMargin(noMargin);    setAlignmentX(Component.CENTER_ALIGNMENT);    setAlignmentY(Component.CENTER_ALIGNMENT);  }  public void setPiece(final byte piece) {    switch (piece) {      case GomokuConstants.COMPUTER_PIECE:        setIcon(computerIcon);        break;      case GomokuConstants.USER_PIECE:        setIcon(playerIcon);        break;      default:        setIcon(noIcon);        break;    }  }  protected void fireActionPerformed(final ActionEvent e) {    if (getIcon().equals(noIcon)) {      super.fireActionPerformed(e);    }  }  public Square getSquare() {    return square;  }  public Dimension getPreferredSize() {    return new Dimension(getIcon().getIconWidth() + 8, getIcon().getIconHeight() + 8);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -