![](/img/trans.png)
[英]I'm attempting to create a small GUI application, but the contents of the JFrame are not showing on screen. How can I fix my code?
[英]I'm attempting to change the image Icon in my JFrame but it's not working, how can I fix it?
我是 java 中使用 GUI 的新手; 我正在嘗試為我的項目更改圖像圖標,但我不知道為什么它不起作用。 我正在為此使用 IntelliJ,我將圖標的圖像(CurrencyExchange.png)移動到我項目中的“src”文件夾。
import javax.swing.*;
import java.awt.*;
public class main {
public static void main(String[] args){
JFrame Frame1 = new JFrame();
Frame1.getContentPane().setBackground(new Color(0x123456));
Frame1.setTitle("Currency Changer");
Frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Frame1.setSize(500,500);
Frame1.setResizable(false);
Frame1.setLocation(430,100);
Frame1.setVisible(true);
ImageIcon image = new ImageIcon("CurrencyExchange.png");
Frame1.setIconImage(image.getImage());
}
}
BufferedImage image = null;
try {
image = ImageIO.read(Objects.requireNonNull(Main.class.getResource("CurrencyExchange.png")));
}
catch (IOException e) {
e.printStackTrace();
}
Frame1.setIconImage(image);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.