Computer Science Canada

Help with images

Author:  Jonny Tight Lips [ Thu Sep 08, 2005 6:22 pm ]
Post subject:  Help with images

Well I have tryed and tryed but I just can't seem to get the image to show up. So far this is what I've got:

code:

import java.awt.*;
import javax.swing.*;
 
 public class Image {
        public static void main(String[] args) {
            new Image();
        }
        Image() {
            JFrame frame = new JFrame();
   
            frame.getContentPane().add(new MyComponent());

            frame.setSize(300, 300);
            frame.setVisible(true);
        }
   
        class MyComponent extends JComponent {
            public void paint(Graphics g) {
                                Image image =     Toolkit.getDefaultToolkit().getImage("homer.gif");
                             g.drawImage(image, 0, 0, this);
            }
        }
    }


Yes this is probably horably wrong but thats as far as I can get. So any help you can give me would be nice. I just can seam to get this. Thx

Author:  rizzix [ Thu Sep 08, 2005 6:28 pm ]
Post subject: 

one big mistake you made is call your class Image... change it to Test or something then try again.

Author:  Jonny Tight Lips [ Fri Sep 09, 2005 3:32 pm ]
Post subject: 

Thx I finaly got it. Time to move on to movement.


: