Reputation: 11
Here's my code:
import java.applet.*;
import java.awt.*;
public class Face extends Applet {
public void paint(Graphics frame) {
// bits of code here
}
public static void main(String[] args) {
String printedOut;
printedOut = printedOut.paint();
System.out.println(printedOut);
}
}
I've looked for different solutions to this, but so far, my search has yielded no results. I ran the code two months ago in school and it worked fine, but now any code I write using the paint method, it just doesn't recognize it. I'm using Netbeans, any solution is greatly appreciated. (I'm trying to make a face.) Also, I know my method of printing it out to the applet is pretty remedial but it works, I'd love to see a different way of doing that, thanks in advance.
Upvotes: 0
Views: 404
Reputation: 285405
This may be causing your error:
String printedOut;
printedOut = printedOut.paint();
String does not have a paint() method. I'd give a recommendation on how to fix this, but I'm not sure what you're trying to accomplish with that line, so I simply recommend deleting the offending line. If you were thinking of creating a Face object within the main method, and then calling its paint(...)
method directly, don't. You will almost never want to call paint directly (unless you're trying to draw the applet to a BufferedImage).
Also as noted in my comments,
Also, regarding your questions at the bottom:
I've looked for different solutions to this, but so far, my search has yielded no results.
You can avoid posting this as it gives us no insight into your actual problem.
I ran the code two months ago in school and it worked fine,
But it wasn't the code that you posted, as there's no way that it would work fine.
but now any code I write using the paint method, it just doesn't recognize it.
I'm not sure what to make of this. If you mean that it doesn't recognize you're calling paint()
on a String object, then that makes sense that it doesn't recognize it, since String doesn't have this method. Your compiler however is recognizing your public void paint(Graphics g)
method.
I'm using Netbeans, any solution is greatly appreciated. (I'm trying to make a face.)
The solution is not use non-compilable code. As for your making a face, that's a completely different issue, and you'll want to post code inside of your paint method that uses the Graphics parameter to achieve this.
Also, I know my method of printing it out to the applet is pretty remedial but it works, I'd love to see a different way of doing that.
Not sure what you're asking here.
Upvotes: 4