about images
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   inter_world
Posted On:   Monday, March 31, 2003 05:16 PM

I need put a image in a application -frame- NOT APPLET, i do:

Toolkit kit = Toolkit.getDefaultToolkit();
Image image = kit.getImage("image.gif");
java.awt.Graphics g;
g.drawImage(imagen,200,200,panel);

I have problems with:
÷The g variable not have been inicialized.

Graphic is an abstract class, how inicialize?
How put the image in a panel in a frame?
what more a need in the code above?

Thanks you.

Re: about images

Posted By:   George_Francis  
Posted On:   Tuesday, April 1, 2003 03:27 PM


You shouldn't need to create your own Graphics object. Just overwrite the paint method of a component such as a Panel and add that to you application.





Panel p = new Panel()

{

 public void paint(Graphics g)

 {

  Toolkit kit = Toolkit.getDefaultToolkit();
  Image image = kit.getImage("image.gif");

  g.drawImage(image,200,200,null);

 }

};

frame.add(p); // or add it to wherever you want it to go



However a simpler solution is to use an ImageIcon:





frame.add(new ImageIcon(getClass().getResource("image.gif")));



I hope this fixes you problem.

About | Sitemap | Contact