package awt; import java.awt.*; class BalkLabel extends Label { public int balkpos; // tussen 0 en Integer.MAX_VALUE public Color lColor,rColor; public BalkLabel(String s,int align) { super(s,align); lColor = Color.blue; rColor = Color.black; } public BalkLabel(String s,int align,Color l,Color r) { super(s,align); lColor = l; rColor = r; } public void setPos(float f) { if (f < 0) balkpos = 0; else if (f >= 1) balkpos = Integer.MAX_VALUE; else balkpos = (int)(f * Integer.MAX_VALUE); repaint(); } public void paint(Graphics g) { Dimension siz = getSize(); int xpos = (int)((long)siz.width * balkpos / (long)Integer.MAX_VALUE); g.setColor(lColor); g.fillRect(0,0,xpos,siz.height); g.setColor(rColor); g.fillRect(xpos,0,siz.width-xpos,siz.height); g.setColor(getForeground()); super.paint(g,false); } }