简体   繁体   English

JAVA:找不到符号:方法画图

[英]JAVA: Can't find symbol: method paint

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. 我两个月前在学校里运行了该代码,它运行良好,但是现在我使用paint方法编写的任何代码都无法识别。 I'm using Netbeans, any solution is greatly appreciated. 我正在使用Netbeans,非常感谢任何解决方案。 (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. (我想做个鬼脸。)另外,我知道我将它打印到applet的方法很补救,但是可以用,我很想看到一种不同的方法,预先感谢。

This may be causing your error: 这可能是导致您的错误的原因:

String printedOut;
printedOut = printedOut.paint();

String does not have a paint() method. 字符串没有paint()方法。 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. 如果您想在main方法中创建一个Face对象,然后直接调用其paint(...)方法,请不要。 You will almost never want to call paint directly (unless you're trying to draw the applet to a BufferedImage). 您几乎永远都不想直接调用画图(除非您试图将小程序绘制到BufferedImage上)。

Also as noted in my comments, 另外,正如我在评论中指出的那样,

  • Applets shouldn't even have main methods as they won't be called. 小程序甚至不应该具有主要方法,因为它们不会被调用。
  • In future posts, please post the full error message. 在以后的帖子中,请发布完整的错误消息。
  • AWT is a dead technology and is at least 2 major generations behind (Swing and now JavaFX). AWT是一项过时的技术,至少落后了2代(Swing,现在是JavaFX)。
  • Applets are a dead technology and have largely been superseded by HTML5/CSS3/JavaScript. 小程序是一种过时的技术,在很大程度上已被HTML5 / CSS3 / JavaScript取代。

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. 但是现在我使用paint方法编写的任何代码都无法识别。

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. 如果您的意思是无法识别您正在对String对象调用paint() ,则可以识别它无法识别,因为String没有此方法。 Your compiler however is recognizing your public void paint(Graphics g) method. 但是,您的编译器正在识别您的public void paint(Graphics g)方法。

I'm using Netbeans, any solution is greatly appreciated. 我正在使用Netbeans,非常感谢任何解决方案。 (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. 至于做鬼脸,这是一个完全不同的问题,并且您需要使用Graphics参数实现此效果的paint方法中发布代码。

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. 另外,我知道将其打印到applet的方法具有很好的补救性,但它确实有效,我很乐意看到执行此操作的另一种方法。

Not sure what you're asking here. 不知道您在这里问什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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