Reputation: 9
In my program there are two buttons and you have to click both of them in order for a system print out to happen. i am having trouble trying to achieve this though.
button[0].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button[0].setEnabled( false );
if( button[1].isEnabled( false) );
System.out.println("you clicked both buttons");
}
});
button[1].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button[1].setBackground(Color.YELLOW);
button[1].setEnabled( false );
if( buttons[0].isEnabled( false) );
System.out.println("you clicked both buttons");
}
});
I am getting errors in the line:
if( buttons[0].isEnabled( false) );
saying
The method isEnabled() in the type Component is not applicable for the arguments (boolean)
I am only a beginner in this so it would be great if someone could help or tell me another way to do this.
Upvotes: 1
Views: 1009
Reputation: 689
Here is your answer:
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
button1.setEnabled(false);
if (!button1.isEnabled() && !button2.isEnabled()) {
System.out.println("you clicked both buttons");
}
}
});
button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
button2.setBackground(Color.YELLOW);
button2.setEnabled(false);
if (!button2.isEnabled() && !button1.isEnabled()) {
System.out.println("you clicked both buttons");
}
}
});
Upvotes: 1
Reputation: 20442
isEnabled
does not require an argument.
Do this:
if( buttons[0].isEnabled() )
Upvotes: 2
Reputation: 6516
Exception is very clear. isEnabled()
hasn't got parameters so you should use it in this way buttons[0].isEnabled()
.
Upvotes: 3