我是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);
}
}
答案 0 :(得分:1)
它正在寻找一个恰好是由JFrame实现的接口的ImageObserver。因此,您可以使用:
g.drawImage(debug, 100, 200, 200, 200, this);