简体   繁体   English

不兼容的类型:int 不能转换为 java.awt.Color

[英]incompatible types: int cannot be converted to java.awt.Color

I'm pretty new in java and I was attempting to debug this little project but I cannot figure out what the issue with the last line is.我是 Java 新手,我试图调试这个小项目,但我无法弄清楚最后一行的问题是什么。

import java.awt.*;
import javax.swing.*;

/**
 * Basic debugging exercise - There are 4 errors in this program.  Find them,
 * correct them, and compile the program to verify that your program matches
 */
public class DebugMe extends JFrame
{
    int x;

    private String message = "Congratulations, the program is working again.";
    Image debug = new ImageIcon(this.getClass().getResource("debug.jpeg")).getImage();
    /**
     * Constructor for objects of class DebugMe
     */
    public DebugMe()
    {
        x = 0;//x was not initialized
        setSize(500, 500);
        setVisible(true);//syntax error there was capital T
    }

    public static void main(String[] args)
    {
        DebugMe myDebugMe = new DebugMe();//syntax error there was a lower case M
        int x;
    }

    public void paint(Graphics g)
    {
        super.paint(g);
        g.drawString("message", 100, 100);
        g.drawImage(debug, 100, 200, 200, 200);
    }
}

It's looking for an ImageObserver which happens to be an interface implemented by JFrame.它正在寻找一个 ImageObserver,它恰好是一个由 JFrame 实现的接口。 So you can just use:所以你可以使用:

g.drawImage(debug, 100, 200, 200, 200, this);

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

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