如何将图像绘制到JPanel或JFrame?
2022-09-03 00:01:48
我如何将图像绘制到JPanel或JFrame,我已经阅读了oracle的教程,但我似乎无法正确理解。我需要将图像“”显示在一组特定的坐标上。这是我到目前为止所拥有的。BeachRoad.png
public class Level1 extends JFrame implements ActionListener {
static JLayeredPane EverythingButPlayer;
static Level1 l1;
public Level1() {
EverythingButPlayer = new JLayeredPane();
BufferedImage img = null;
try {
img = ImageIO.read(new File("BeachRoad.png"));
} catch (IOException e) {
}
Graphics g = img.getGraphics();
g.drawImage(img,0, 0, EverythingButPlayer);
this.add(EverythingButPlayer);
}
在主要(),
l1 = new Level1();
l1.setTitle("poop");
l1.setSize(1920, 1080);
l1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1.setVisible(true);
提前致谢!