Hey guys, it's the first post for me here.
I'm simply trying to make a gui for managing images for my purpose, but i fall at the first step: I'm actually not able to display an image, whether it would be a .gif or .jpg and i don't know why!
I tried several code found on internet, after the first one, but none works. Do you find any problem on it?
Thank you
//--------MY PANEL FOR VIEWING IMAGE--------- package graph2D; import java.awt.Graphics; import java.awt.Image; import java.awt.MediaTracker; import java.awt.Toolkit; import javax.swing.JPanel; class PannelloConImmagine extends JPanel { private Image miaImmagine; public PannelloConImmagine() { miaImmagine = Toolkit.getDefaultToolkit().getImage("pippo.gif"); MediaTracker tracker = new MediaTracker(this); tracker.addImage(miaImmagine, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { e.printStackTrace(); } } public void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(miaImmagine, 0,0, this); } } //------------GUI------------- package graph2D; import java.awt.*; import javax.swing.*; public class ProvaPannelloConImmagine extends JFrame { PannelloConImmagine myPanel; public ProvaPannelloConImmagine() { this.setTitle("PROVA"); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); myPanel = new PannelloConImmagine(); this.add(myPanel); this.setSize(600,600); this.setVisible(true); pack(); } public static void main(String[] args) { ProvaPannelloConImmagine pjf = new ProvaPannelloConImmagine(); } }
it is supposed that i placed the image "pippo.gif" in my project "src" folder, isn't it? anyway I tried to add a new folder to my build Path, and place pippo.gif on it, but it doesn't work.