简体   繁体   中英

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.

RadioButton is a class, but you're trying to get the text and highlight info from it as if it were an instance of that class. It seems like you want to be working with an instance of a RadioButton , and not the class itself.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM