Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Lorraine Stephens   on Jul 10 In Java Category.

  
Question Answered By: Khadeeja Malik   on Jul 10

Check out this URL

www.ecs.umass.edu/.../
drawingImages.html

Its from the 2D graphics section of the Java tutorial.

In the example displays an image  on an applet and scales it. In your
case, you want to display an image on a JPanel (I'm assuming that you
are using Swing but it should work if you are using the Panel object
from AWT).

import javax.swing.*;

public class ImagePanel extends JPanel {
Image image;

...

image = getImage(getCodeBase(), "../images/rocketship.gif");

...

public void paint(Graphics g) {
g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
}

The getWidth() and getheight() should return the width and height of
the JPanel.

Share: 

 
 
Didn't find what you were looking for? Find more on loading gifs etc Or get search suggestion and latest updates.


Tagged: