vendredi 13 mars 2015

How to access getter methods of another class into main method



I have an abstract class GUIelements, with two (non-static) "getter methods";



public boolean isHighlighted(){
return highlighted;
}

public String getText(){
return text;
}


I'm trying to convert the number entered with StdDraw into degrees Celcius in the main method. Here's the method:



public static void calculate(){
String choice = (String)RadioButton.getText();

if(RadioButton.isHighlighted() && choice.equals("Temperature(C toF)")){

String text = Text.getText();
double number = Double.parseDouble(text);
double result = number*1.8 + 32;
}
}


RadioButton is a class that draws 3 circles and let's the user select which conversion they want.


My error is telling me that:


Error: Cannot make a static reference to the non-static method getText() from the type GUIelements.


I know that this is right, as I wouldn't be able to access this text (converted into a number) because getText() is non-static. But I have no other idea of how to get this text and subsequently convert it.




Aucun commentaire:

Enregistrer un commentaire