如何在第二次点击时使jbutton免疫

发布于 2025-02-05 05:31:10 字数 207 浏览 3 评论 0原文

我正在制作tic tac toe应用程序,首先单击按钮后,它要么获得“ O”或“ X”文本,因此我想避免使用第二次单击,就像我想让它免疫到到目前为止

if (!pola[i].getText().isEmpty()) {
                pola[i].setEnabled(true);
            }

Im making tic tac toe app, after first click on the button it get either "O" or "X" text and I want to avoid second click, like I want to make it immune to second click

if (!pola[i].getText().isEmpty()) {
                pola[i].setEnabled(true);
            }

so far I got this,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然 2025-02-12 05:31:11

在单击按钮时单击单击将其设置为true,然后在“ ”执行代码之前检查!可以做jframe.remove(pola [i]);其中jframe是您正在使用的框架,如果您希望它再次可进行交互,则将其添加jframe.add(pola [i]) );

make a boolean clicked set it to true when the button is clicked, then in the action listener method check if !clicked before you execute the code, or maybe if u want u can do JFrame.remove(pola[i]); where JFrame is the frame you are using and if you want it to be interactable again you add it JFrame.add(pola[i]);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文