📄 printcard..java~1~
字号:
/** * Call this method with true (or false) as argument if you want (or not) a text label inside. * @see #isTextInside */ public void setTextInside(boolean bool) { textInside=bool; repaint(); } /** * Return true if a label will be shown inside. * @see #setTextInside */ public boolean isTextInside() { return textInside; } /** * Set the style of the code to one of the two available style. * @see #CODE3OF9 * @see #CODE3OF9CHK * @see #getStyle */ public void setStyle(int styl) { switch (styl) { case CODE3OF9: case CODE3OF9CHK: style=styl; Encode(); return; } style=CODE3OF9; Encode(); } /** * return the style of the barcode currently used. * @see #CODE3OF9 * @see #CODE3OF9CHK * @see #setStyle */ public int getStyle() { return style; } /** * set the color of the background to the specified color. * @param c the color to be used * @see #getBackgroundColor * @see #setForegroundColor * @see #getForegroundColor */ public void setBackground(Color c) { backColor=c; repaint(); } /** * return the color used for the background. * @return the color used * @see #setBackgroundColor * @see #setForegroundColor * @see #getForegroundColor */ public Color getBackground() { return backColor; } /** * set the color of the foreground to the specified color. * @param c the color to be used * @see #getBackgroundColor * @see #setBackgroundColor * @see #getForegroundColor */ public void setForeground(Color c) { foreColor=c; repaint(); } /** * return the color used for the foreground. * @return the color used * @see #setBackgroundColor * @see #getBackgroundColor * @see #setForegroundColor */ public Color getForeground() { return foreColor; } /** * Sets the font of the component. * @param fnt the font * @see #getFont */ public void setFont(Font fnt) { font=fnt; repaint(); } /** * Gets the font of the component. * @see #setFont */ public Font getFont() { return font; } /** * Set the alignment of text inside the bar code. Three option are available. * @see #BASELINE * @see #MIDDLELINE * @see #TOPLINE * @see #getTextAlign */ public void setTextAlign(int align) { switch (align) { case BASELINE: case MIDDLELINE: case TOPLINE: textAlign=align; repaint(); return; } textAlign=TOPLINE; repaint(); } /** * Set the alignment of text inside the bar code. Three option are available. * @see #BASELINE * @see #MIDDLELINE * @see #TOPLINE * @see #setTextAlign */ public int getTextAlign() { return textAlign; } /** * Paints the component. * @param g the specified Graphics window */ public synchronized void paint (Graphics g) { int width=getSize().width; int height=getSize().height; Font ft=new Font("Courier",0, getSize().width/25); g.setFont(ft); FontMetrics fm=g.getFontMetrics(font); int fmAscent=fm.getAscent(); // calcolo la lunghezza della etichetta codificata labelLength= filledStringToEncode.length()*16*narrowestDim; // le dimensioni dei margini e l'altezza della etichetta marginWidth=(width-labelLength)/2; marginHeight=(height-labelLength)/2; if ( textInside ) { if ( textAlign==BASELINE ) labelHeight=height; if ( textAlign==MIDDLELINE ) labelHeight=height-(int)(fmAscent/2); if ( textAlign==TOPLINE ) labelHeight=height-fmAscent; } else { labelHeight=height; } g.setColor(backColor); g.fillRect(0,0,width,height); int length=encodedString.length(); int yp=(int)(labelHeight/4); int x0=0,y0=0,x=0,y=0; int wid=0; x0=(int) marginWidth; y0=0; x=0; y=0; for ( int i=0;i<length ;i++ ) { if (i%2==0) g.setColor(foreColor); else g.setColor(backColor); if ( Character.digit(encodedString.charAt(i),10)==1 ) wid=(int)(wideToNarrowRatio*narrowestDim); else wid=(int)narrowestDim; g.fillRect(x+x0,(int)(labelHeight/4+2*fm.getHeight()+2+yp),wid,(int)labelHeight/4); x+=wid; } g.drawString(stringName+" "+" "+stringPosition,width/4,(int)labelHeight/2); g.drawString(stringCompany,width/4,(int)(labelHeight/4+fm.getHeight()+1+yp)); if ( textInside ) { int k=fm.stringWidth(filledStringToEncode); int h=getSize().height; int mlk2=(int)(marginWidth+labelLength/2-k/2); g.setColor(backColor); g.fillRect(mlk2,h-fmAscent,k,fmAscent); g.setColor(foreColor); g.drawString(filledStringToEncode,mlk2,h); } Image printImage; printImage = new javax.swing.ImageIcon("e:/image/xh.gif").getImage(); int iwidth=printImage.getWidth(this); int iheight=printImage.getHeight(this); double pwidth=width/5; double pheight=labelHeight/3; double scalex=pwidth/iwidth; double scaley=pheight/iheight; if(scalex>scaley) g.drawImage(printImage, 1, 1,(int)(iwidth*scaley),(int)(pheight), null); //g.clearRect( 1, 1,(int)(iwidth*scaley),(int)(pheight)); else g.drawImage(printImage, 1, 1,(int)(pwidth),(int)(iheight*scalex), null); Image printImage1; printImage1 = new javax.swing.ImageIcon("e:/image/zt.gif").getImage(); int iwidth1=printImage1.getWidth(this); int iheight1=printImage1.getHeight(this); double pwidth1=3*width/5; double pheight1=labelHeight/3; double scalex1=pwidth1/iwidth1; double scaley1=pheight1/iheight1; if(scalex1>scaley1) g.drawImage(printImage1, 2*width/10, 1,(int)(iwidth1*scaley1),(int)(pheight1), null); //g.clearRect( 2*width/10, 1,(int)(iwidth1*scaley1),(int)(pheight1)); else g.drawImage(printImage1, 2*width/10, 1,(int)(pwidth1),(int)(iheight1*scalex1), null); } private void stringValidate() throws IllegalArgumentException { //valido la stringa secondo il codice int len=stringToEncode.length(); for ( int i=0;i<len ;i++ ) { if (alphabet3of9.indexOf(stringToEncode.charAt(i))==-1 || stringToEncode.indexOf("*")!=-1) throw new IllegalArgumentException("only digits and upper case letter for 3of9"); } } private void Encode() { filledStringToEncode=new String(stringToEncode); // aggiungo il check char if ( style==CODE3OF9CHK ) { int leng=stringToEncode.length(); int sum=0; for ( int i=0;i<leng ;i++ ) { sum+=alphabet3of9.indexOf(stringToEncode.charAt(i)); } sum=sum%43; filledStringToEncode+=alphabet3of9.charAt(sum); } // ci aggiungo i caratteri di start e stop filledStringToEncode="*"+filledStringToEncode+"*"; //codifico la stringa secondo il codice encodedString=""; int length=filledStringToEncode.length(); for ( int i=0;i<length-1 ;i++ ) { encodedString += coded3of9Char[alphabet3of9.indexOf(filledStringToEncode.charAt(i))]; encodedString += intercharacterGap; } encodedString += coded3of9Char[alphabet3of9.indexOf(filledStringToEncode.charAt(length-1))]; repaint(); } // end Encode3of9() /* * * La sola gestione degli eventi necessaria * * a mostrare la about frame * */ /*Rectangle getModleExtent() {Iterator elements=this.getModel().getIterator(); Rectangle rect=new Rectangle(); Element element; while(elements.hasNext()) { element=(Element)elements.next().; rect.add(element.getBounds()); } if(rect.width==0) rect.width=1; if(rect.height==0) rect.height=1; return rect;}*/}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -