错误:不兼容的类型:ImageObserver无法转换为java.awt.image.ImageObserver

时间:2017-11-22 23:07:31

标签: java graphics

尝试在java中显示图像,但上面列出的错误会不断弹出。我该如何解决?

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

public class ImageObserver{

    public void paintComponent (Graphics g) {
        Image image = new ImageIcon("Hyperspace.JPEG").getImage();
        g.drawImage(image, 3, 4, this);
    }

    public static void main(String[] args) {

        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        frame.getContentPane().add(panel);
        frame.setSize(1000, 1000);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

0 个答案:

没有答案