Can anyone help me with my issue? I can't seem to figure out how I can make a jButton hide after it has been clicked ONCE.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//The hide code would go here
}
First of all, just use implement interface actionListener to your class:
public class test implements ActionListener {
Next, add actionListener to your button:
button.addActionListener(this);
Last in the implemented actionPerformed method:
public void actionPerformed(ActionEvent e){
if(e.getSource.equals(button)) button.setVisible(false); //set's the buttons visibility to false.
}
**Edit: If you want to do it for one button click, in the actionPerformed method if statement you can also do: **
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
}
}
Hope this helps.
你在找
jButton1.setVisible(false);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.