Reputation: 436
I have created a class that extends JButton which I pass to another class constructor. However, when I am trying to access button`s 'getSubmitted()' method it pops me an error message saying that 'Cannot resolve method getSubmitter()'... I cannot understand why is that happening as the methods and classes are both public and Button is assigned to a variable...
public class ButtonSubmit extends JButton{
private boolean submitted;
/*
...
*/
public boolean getSubmitted(){
return this.submitted;
}
public class ServerConnector{
privaet JButton submitBtn;
public ServerConnector(JButton submitBtn){
this.submitBtn = submitBtn;
}
/*..*/
public void start(){
while(true){
if(this.submitBtn.getSubmitted()){
/**/
}
/**/
}
}
}
Upvotes: 0
Views: 351
Reputation: 92377
You need to use the type ButtonSubmit
in the constructor and for the field:
public class ServerConnector{
private ButtonSubmit submitBtn;
public ServerConnector(ButtonSubmit submitBtn){
this.submitBtn = submitBtn;
}
/*..*/
public void start(){
while(true){
if(submitBtn.getSubmitted()){
/**/
}
/**/
}
}
}
You are trying to access a member of a type (JButton
) that doesn't have the desired method. So you need the type ButtonSubmit
that actually has this method.
Upvotes: 2