如何在第二次点击时使jbutton免疫
我正在制作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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在单击按钮时单击单击将其设置为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 doJFrame.remove(pola[i]);
where JFrame is the frame you are using and if you want it to be interactable again you add itJFrame.add(pola[i]);