如何将 netbeans 中的“确定”按钮设为空
我使用此方法在“确定”按钮(Netbeans Jframe)中输入一个值:
public void change (java.awt.event.ActionEvent evt) {
if (turn == true) {
JButton button = (JButton) evt.getSource();
button.setText("X");
turn = false;
button.setEnabled(false);
}
else {
JButton button = (JButton) evt.getSource();
button.setText("O");
turn = true;
button.setEnabled(false);
}
然后我想要一个重置按钮,将“确定”按钮内的值返回为空(因此它是空白的)我目前有以下内容,但它不起作用。
public void reset (java.awt.event.ActionEvent evt) {
if (reset == true)
{
JButton button = (JButton) evt.getSource();
button.setEnabled(true);
button.setText("");
turn = false;
}
我的代码是什么?
I am entering a value into the OK button (Netbeans Jframe) by using this method:
public void change (java.awt.event.ActionEvent evt) {
if (turn == true) {
JButton button = (JButton) evt.getSource();
button.setText("X");
turn = false;
button.setEnabled(false);
}
else {
JButton button = (JButton) evt.getSource();
button.setText("O");
turn = true;
button.setEnabled(false);
}
I then later want to have a reset button that returns the value inside the OK button to nothing (so it is blank) i currently have the following but it does not work.
public void reset (java.awt.event.ActionEvent evt) {
if (reset == true)
{
JButton button = (JButton) evt.getSource();
button.setEnabled(true);
button.setText("");
turn = false;
}
what would be my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码仅重置已单击的按钮:
您需要遍历所有要重置的按钮:
此代码假设要重置的按钮放置在名为
buttonsToReset
的按钮集合或数组中。Your code only resets the button which has been clicked :
You need to iterate through all the buttons to reset:
This code assumes that the buttons to reset are placed in a collection or array of buttons named
buttonsToReset
.