Hi friends , How can I add a picture to a frame in java(AWT)? thanks for your attention =)
here is what I did (exactly same as what was written in RoseIndia):but it doesn't show me any image.what's wrong with it ? public class AwtImage extends Frame { Image img; public static void main(String[] args) { AwtImage ai = new AwtImage(); } public AwtImage() { super("Image Frame"); MediaTracker mt = new MediaTracker(this); img = Toolkit.getDefaultToolkit().getImage("icon_confused.gif"); mt.addImage(img, 0); setSize(400, 400); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); } }); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { if (img != null) g.drawImage(img, 100, 100, this); else g.clearRect(0, 0, getSize().width, getSize().height); } }
No need!thanks! I found the problem ... unlike the code I've put here , I was trying to add a .jpg image instead of .gif.
Makes sense. :)
Join our real-time social learning platform and learn together with your friends!