這裏是我想要導入圖片的代碼,我想在Java GUI上顯示它們。如何使用Eclipse在GUI中添加圖像?此代碼未顯示圖像
AddingImages(){
setLayout(new FlowLayout());
image1 = new ImageIcon(getClass().getResource("Capture1.PNG"));
label1 = new JLabel("Image 1");
add(label1);
image2= new ImageIcon(getClass().getResource("Capture1.PNG"));
label2 = new JLabel("Image 2");
add(label2);
}
public static void main(String[] args){
AddingImages ai = new AddingImages();
ai.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ai.setVisible(true);
ai.pack();
ai.setTitle("Adding Images in GUI");
}
}
*「並解釋包()屬性」 * 1)你似乎弄錯了這個Q&A的一站式服務檯現場。如果還有其他問題,請在單獨的問題主題上詢問他們。 2)但首先,請參閱Java Docs的方法,這是他們的目的。 –
至於加載圖像的問題:如果我們知道顯示的代碼包以及相對於該包的圖像位置,我們將能夠更好地幫助您。令人驚訝的是,我們無法通過我們安裝在家中的間諜攝像頭看到這些信息。 –
@AndrewThompson圖像的位置與包的位置相同(即bin文件夾) –