-2

I am a completely noob with Java. I can't figure out what is the problem with my code.

Eclipse says pythagorasComponent(TextAttribute) is undefined for the type object.

Can you give me a hand please?

public class Pythagoras {
public void pythagorasComponent(TextAttribute two) {
    AttributedString to = new AttributedString("Your \u25b2's c2 equals 
with");
    super.pythagorasComponent(two);
    to.addAttribute(TextAttribute.SUPERSCRIPT, 
 TextAttribute.SUPERSCRIPT_SUPER, 15, 16);

}
//I imported the following: 
//import java.awt.font.TextAttribute;
//import java.lang.Math;
//import java.util.Scanner;
//import java.text.AttributedString;
RobertMyles
  • 2,673
  • 3
  • 30
  • 45
winnergo
  • 101
  • 11

1 Answers1

0

Your are confused as to what the super keyword means. Plese see this page on super.

To assign the superscript attribute to an AttributedString, you should do as illustrated in this example.

This is mainly done by creating the AttributedString as you have done and assign the superscript property by using the indices such as:

AttributedString test = new AttributedString("test superscript and bold");
test.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, 5, 25); 

Where the 5 and 25 are the start and end indices of the superscript part of the String.

TM00
  • 1,330
  • 1
  • 14
  • 26