Sto provando ad aggiungere un'immagine a un fotogramma ma sembra che non funzioni. L'immagine creata da un ImageIcon dal file specificato. Il file immagine si trova nella directory della giunzione e il file java esiste.Come aggiungere un ImageIcon a un JFrame?
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class image {
public static void main(String args[])
{
TimeFrame frame = new TimeFrame();
}
}
class TimeFrame extends JFrame
{
//Image icon = Toolkit.getDefaultToolkit().getImage("me.jpg");
ImageIcon icon = new ImageIcon("me.jpg");
JLabel label = new JLabel(icon);
public TimeFrame(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("My Frame");
setSize(500,400);
//this.setIconImage(icon);
add(label,BorderLayout.CENTER);
setVisible(true);
}
}
Si prega di dare un'occhiata a come [aggiungere immagini a TUO PROGETTO] (http://stackoverflow.com/a/9866659/1057230) e questa [risposta] (http://stackoverflow.com/a/11372350/1057230) per ulteriori chiarimenti, se lo fai manualmente (senza IDE). –