/** *
Überschrift:
* *Beschreibung:
* *Copyright: Copyright (c) 2005
* *Organisation:
* * @author Andrea Spirka, sven Eisenhauer * @version 1.0 */ import java.awt.*; import java.io.File; import javax.swing.*; class ViewComponent extends JComponent { transient private Image image; /* (non-Javadoc) * @see javax.swing.JComponent#paintComponent(java.awt.Graphics) */ protected void paintComponent( Graphics g ) { if ( image != null ) g.drawImage( image, 10, 10, this ); centerImage(g,this,image); } public ViewComponent(){ } /** * @param file */ public void setImage( File file) { image = Toolkit.getDefaultToolkit().getImage( file.getAbsolutePath() ); if ( image != null ) { repaint(); } } /** * @param g * @param component * @param image */ public static void centerImage( Graphics g, Component component, Image image ) { g.setColor( component.getBackground() ); Dimension d = component.getSize(); g.fillRect( 0, 0, d.width, d.height ); g.drawImage( image, ( d.width - image.getWidth( null ) ) / 2, ( d.height - image.getHeight( null ) ) / 2, null ); } }