Présentation
Cette classe permet d'afficher une image comme composant (extension de JPanel). Si l'image est plus petite que l'espace à disposition, elle sera centrée; dans le cas contraire l'image sera zoomée de telle manière à s'adapter et couvrir tout l'espace disponible. Cette classe fonctionne également si l'image se trouve empaquetée dans le même fichier jar que l'application.
|
Téléchargement
|
Compatibilité
|
// Updates: 2004.07.16 import java.awt.*; import javax.swing.*; /** * Displays a centered image in the available area. If the picture is too big * (width or height), a zoom will be applied in order to show the full image. * This class works also if the picture is in a jar file. * @author Michel Deriaz */ /** * Loads the specified image, which must be a JPG, a GIF, or a PNG. * @param file the file to load */ repaint(); } super.paintComponent(g); if (img == null) return; int w = img.getWidth(this); int h = img.getHeight(this); boolean zoom = (w > getWidth() || h > getHeight()); if (zoom) g.drawImage(img, 0, 0, getWidth(), getHeight(), this); else g.drawImage(img, (getWidth()-w)/2, (getHeight()-h)/2, this); } }
Developpez.com décline toute responsabilité quant à l'utilisation des différents éléments téléchargés.




