有人可以帮助我解决我的问题吗?我似乎无法弄清楚如何在单击一次后如何制作jbutton隐藏。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//The hide code would go here
}
您正在寻找
jButton1.setVisible(false);
首先,只需在您的类中使用" enase insterface actionlistener:
"public class test implements ActionListener {
接下来,将ActionListener添加到您的按钮:
button.addActionListener(this);
在实现的Action Performed方法中最后一次:
public void actionPerformed(ActionEvent e){
if(e.getSource.equals(button)) button.setVisible(false); //set's the buttons visibility to false.
}
**编辑:如果您想单击一个按钮,请在Action Performed方法中单击,如果语句您也可以做:**
public void actionPerformed(ActionEvent e){
if(e.getSource.equals(button) && !once){
button.setVisible(false);
once = true; //once is a boolean which shows if the button has been clicked once
}
}
希望这会有所帮助。