java - 似乎无法锁定我的 Jbutton。错误 : Cannot find symbol

标签 java user-interface actionlistener

这是我正在尝试制作的井字游戏的源代码,我希望玩家按下 Jbutton 然后禁用该按钮。我知道该命令是 setEnbale(false) 以使其锁定,但它对我不起作用。我有 9 个按钮,它们分配有 Action 监听器。该程序能够通过 Action 监听器区分玩家 1 和玩家 2。但是,当我也尝试锁定单元格时,出现“错误:找不到符号。”。我到底做错了什么?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class TicTacToe extends JFrame
{
private final int HEIGHT = 450;
private final int WIDTH = 500;
private static JButton [] button = new JButton[9];
private static Action [] playerTurn = new Action[9];
private static JLabel [] label;
private int player = 1;
private static int lockButtons = 0;

public TicTacToe ()
{
    setTitle( " Tic Tac Toe ");
    setSize( HEIGHT, WIDTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setLayout(new GridLayout(4,3));

    int num = 0;
    for(int i = 0; i < 9; i++ )
    {

        button[i] = new JButton( "B" + i + 1);
        playerTurn[i] = new Action();
        add(button[i]);
        button[i].addActionListener(playerTurn[i]);
    }


    setVisible(true);
}


private class Action implements ActionListener
{
    public void actionPerformed(ActionEvent playerMove)
    {
        //Get button pressed using GetSource Command
        JButton whatPlayer=(JButton)(playerMove.getSource());

            if(player == 1)
            {
                player++;
                whatPlayer.setText("player1");
                whatPlayer.setEnable(false); // this is what is cause me the error
                return;
            }   

            JOptionPane.showMessageDialog(null,"Thank You For Your Input");

            if (player == 2)
            {
                player--;
                whatPlayer.setText("player2");
                return;
            }



    }
}

public static void main(String[] arg)
{
    new TicTacToe();
}   
}

最佳答案

使用,

whatPlayer.setEnabled(b) 不是 whatPlayer.setEnable(b)

关于java - 似乎无法锁定我的 Jbutton。错误 : Cannot find symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22574563/

相关文章:

user-interface - 在窗口调整大小时重新渲染meteor.js?

java - Java 中的文本框 keyListener

java - 如何从 ImageView 获取图像 id?

java - 为什么我应该在 httpPost() 之后重启 Wifi

java - Java正则表达式中的最大组数

java - 当条件被 Action 监听器改变时中断 while 循环

java - 创建新 Action 监听器时找不到符号

java - Android - 指定的 child 已经有一个 parent 。您必须先对 child 的 parent 调用 removeView()

java - 比较方法违规和stackoverflow

iphone - 为什么这个bar按钮是黑色的,看不清楚?