用Java覆盖现有图像

时间:2019-01-21 18:12:00

标签: java image file interface jbutton

在代码运行时,如何使用按钮和ifs应用图像,然后覆盖现有图像?我尝试了越来越多的解决方案,但没人能解决。 感谢您的帮助。

尝试的解决方案:

BufferedImage img = ImageIO.read(new File("1.PNG"));
JLabel pic = new JLabel(new ImageIcon(img));
pic.setBounds(420, 50, 300, 300);
add(pic);

JLabel imgLabel = new JLabel(new ImageIcon("1.PNG"));
imgLabel.setBounds(420, 50, 300, 300);
add(imgLabel);

File foto = new File("1.PNG");
JLabel img = new JLabel(new ImageIcon(foto.getName()));
img.setBounds(420, 50, 300, 300);
add(img);

0 个答案:

没有答案