我在框架上显示图像时遇到问题。当图片显示时,左上角没有到达指定的 (0,0),当我第一次运行它时,窗口的背景也会呈现窗口后面的任何视觉组件。有人知道出了什么问题吗?提前致谢-
import java.awt.image.ImageObserver;
import java.io.File;
import javax.imageio.*;
import javax.swing.*;
public class Window extends JFrame{
//the pictures
Image testImage = null;
Image backPic = null;
//constructor
Window(){
super("window");
this.startWindow();
}
public void startWindow(){
Image customIcon = Toolkit.getDefaultToolkit().getImage("iconImage.gif");
testImage = Toolkit.getDefaultToolkit().getImage("tester.gif");
backPic = Toolkit.getDefaultToolkit().getImage("black.png");
setSize(700,600);
setIconImage(customIcon);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
setLocationRelativeTo(null);
}
public void paint(Graphics g){
g.drawImage(testImage,0,0,null);
}
}