Lightweight Example: DecoBox


class DecoBox extends Component 
{ 
  String Text; 

  public void setText ( String text ) { 
    Text = text; 
  } 

  public void paint ( Graphics g ) { 
    Dimension size = getSize(); 
    size.width -=2; size.height -= 7; 

    g.setColor( Color.white); 
    g.drawRect( 1, 6, size.width, size.height); 
    g.setColor( Color.black); 
    g.drawRect( 0, 5, size.width, size.height); 

    if ( Text != null ) { 
      FontMetrics fm = getToolkit().getFontMetrics( getFont()); 
      int w = fm.stringWidth( Text); 
      g.setColor( getBackground()); 
      g.fillRect( 15, 5, w + 6, 3); 
      g.setColor( Color.black); 
      g.drawString( Text, 18, 10); 
    } 
  } 

  public boolean contains ( int x, int y ){ 
    return false; // we are just a decoration 
  } 
}