import java.awt.*; class hline extends Panel{ String s; public hline (String s){ this.s = s; } public Dimension preferredSize(){ Dimension d = new Dimension(0,3); if (s != null && s.length() > 0){ FontMetrics met = getGraphics().getFontMetrics(); d.height = met.getHeight(); d.width = met.stringWidth(s)+4; } return d; } private void draw3dline (Graphics g, int x, int y, int end){ g.setColor (Color.black); g.drawLine (x,y,end,y); g.setColor (Color.white); y++; g.drawLine (x+1,y,end,y); } public void paint (Graphics g){ Rectangle r = bounds(); int y = r.height/2; if (s == null || s.length() == 0){ draw3dline (g,0,y,r.width); }else{ Dimension d = preferredSize(); int side = (r.width - d.width)/2; g.setColor (Color.black); g.drawString (s,side+2,r.height-4); draw3dline (g,0,y,side); draw3dline (g,r.width-side,y,r.width); } } }