int x = comp.getX();
int y = comp.getY();
g.translate(x,y);
cursor.translate(-x,-y);
int w = comp.getWidth();
int h = comp.getHeight();
// draw background
g.setColor(new Color(1.0f, 0.5f, 0.5f, 0.3f));
g.fillRect(0,0,w,h);
g.setColor(Color.red);
g.drawRect(0,0,w,h);
// if the mouse is over this component
if(comp.contains(cursor)) {
// draw the text
String cls_name = comp.getClass().getName();
Graphics2D g2 = (Graphics2D)g;
Font fnt = g.getFont();
FontMetrics fm = g.getFontMetrics();
int text_width = fm.stringWidth(cls_name);
int text_height = fm.getHeight();
int text_ascent = fm.getAscent();
// draw text background
g.setColor(new Color(1f,1f,1f,0.7f));
g.fillRect(0,0,text_width,text_height);
g.setColor(Color.white);
g.drawRect(0,0,text_width,text_height);
// draw text
g.setColor(Color.black);
g.drawString(cls_name, 0, 0+text_ascent);
}
if(comp instanceof Container) {
Container cont = (Container)comp;
for(int i=0; i<cont.getComponentCount(); i++) {
Component child = cont.getComponent(i);
rPaint(child,g);
}
}
cursor.translate(x,y);
g.translate(-x,-y);