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

时间:2018-10-09 01:41:16

标签: java

我是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);
    }
}

1 个答案:

答案 0 :(得分:1)

它正在寻找一个恰好是由JFrame实现的接口的ImageObserver。因此,您可以使用:

g.drawImage(debug, 100, 200, 200, 200, this);
相关问题