00001 package dionarap;
00002
00003 import java.awt.Dimension;
00004 import java.awt.Graphics;
00005 import java.awt.Graphics2D;
00006 import java.awt.font.TextLayout;
00007 import java.awt.geom.Rectangle2D;
00008
00009 import javax.swing.ImageIcon;
00010 import javax.swing.JPanel;
00011
00022 public class PaintGraphic extends JPanel{
00026 private static final long serialVersionUID = 8779958318489877425L;
00027
00028
00032 private String bezeichnung;
00033
00034
00036 private ImageIcon icon;
00037
00038
00045 public PaintGraphic(String bezeichnung, ImageIcon icon)
00046 {
00047 this.bezeichnung = bezeichnung;
00048 this.icon = icon;
00049
00050 this.setPreferredSize(new Dimension(60, 80));
00051 }
00052
00059 @Override
00060 protected void paintComponent(Graphics graphics)
00061 {
00062 super.paintComponent(graphics);
00063
00064 Graphics2D graphics2d = (Graphics2D)graphics;
00065 graphics2d.drawImage(this.icon.getImage(), 5, 5, this);
00066
00067 TextLayout layout = new TextLayout(this.bezeichnung, graphics2d.getFont(), graphics2d.getFontRenderContext());
00068 Rectangle2D rect = layout.getBounds();
00069 graphics2d.drawString(this.bezeichnung, 30 - (int)rect.getCenterX(), 65);
00070 }
00071 }