it can't be void because it returns a string from the textField to the public void paint(Graphics g)
No. It doesn't return anything. To return something to the
paint method the
paint method would have to call it first, eg,
public String getString { ... }
public void paint(Graphics g) {
...
String s = getString();
...
}
Actually, it's a constructor which is the only kind of method that does not have a return type in its method declaration. Java calls the constructor for class initialization. With the return type included, viz,
void the method was never called.