package postal; import java.awt.*; import java.util.*; public class PostalBarCode extends Component { public PostalBarCode() { setForeground(Color.black); setBackground(Color.white); } public void paint(Graphics g) { int offset = 0; int i = 0; Bar bar = null; g.setColor(this.getBackground()); g.fillRect(0,0,this.WIDTH, this.HEIGHT); g.setColor(this.getForeground()); g.fillRect(BUFFER_SPACE, MAX_HEIGHT - FullBar.sole().getHeight(), FullBar.sole().getWidth(), FullBar.sole().getHeight()); for (i = 0; i < mv_Bars.size(); i++) { bar = (Bar)mv_Bars.elementAt(i); offset = MAX_HEIGHT - bar.getHeight(); g.fillRect((i+1) * mi_Space + BUFFER_SPACE, offset, bar.getWidth(), bar.getHeight()); } g.fillRect((i+1) * mi_Space + BUFFER_SPACE, MAX_HEIGHT - FullBar.sole().getHeight(), FullBar.sole().getWidth(), FullBar.sole().getHeight()); } public void clearCode() { mv_Bars.removeAllElements(); } public void drawFullBar() { mv_Bars.addElement(FullBar.sole()); repaint(); } public void drawSmallBar() { mv_Bars.addElement(SmallBar.sole()); repaint(); } public void setSpacing(int space) { mi_Space = space; } public void setFullBarHeight(int height) { if (height > SmallBar.sole().getHeight() && height < MAX_HEIGHT) { FullBar.sole().setHeight(height); } } public void setSmallBarHeight(int height) { if (height > 0 && height < FullBar.sole().getHeight()) { SmallBar.sole().setHeight(height); } } private int MAX_HEIGHT = 30; private int BUFFER_SPACE = 10; private int mi_Space = 5; private Vector mv_Bars = new Vector(); }