Reputation: 267
I have two buttons in my Jframe: button1 and button2. Both buttons have their respective codes to execute when they got clicked. However button2 should only be visible when a certain condition in button1 is satisfied. Need help. How should I do this?
Upvotes: 2
Views: 220
Reputation: 1335
You can use Action Event to use visiblity of buttons
button1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// Add Button Action Handler here
button1.setVisible(false);
button2.setVisible(true);
}
}
button2.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// Add Button Action Handler here
button2.setVisible(false);
button1.setVisible(true);
}
}
Upvotes: 1
Reputation: 1082
Initially put
button2.setVisible(false);
In the click event of button1 when condition is satisfied set
button2.setVisible(true);
Upvotes: 1