001package headfirst.proxy.virtualproxy; 002 003import java.awt.Graphics; 004 005import javax.swing.Icon; 006import javax.swing.JComponent; 007 008@SuppressWarnings("serial") 009class ImageComponent extends JComponent { 010 private Icon icon; 011 012 public ImageComponent(Icon icon) { 013 this.icon = icon; 014 } 015 016 public void setIcon(Icon icon) { 017 this.icon = icon; 018 } 019 020 public void paintComponent(Graphics g) { 021 super.paintComponent(g); 022 int w = icon.getIconWidth(); 023 int h = icon.getIconHeight(); 024 int x = (800 - w)/2; 025 int y = (600 - h)/2; 026 icon.paintIcon(this, g, x, y); 027 } 028}