⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code39.java~3~

📁 会议名片管理程序 3/9条形码生成
💻 JAVA~3~
字号:
package cardmanager;import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.Properties;import java.awt.font.FontRenderContext;import java.awt.print.*;import java.io.*;import java.awt.image.*;import java.awt.geom.*;import java.util.*;import javax.swing.event.*;import java.util.Vector;import cardmanager.*;public class Code39 extends JLabel {  private static String[] CODEA =new String[]{                                         "1010001110111010",                                         "1110100010101110",                                         "1011100010101110",                                         "1110111000101010",                                         "1010001110101110",                                         "1110100011101010",                                         "1011100011101010",                                         "1010001011101110",                                         "1110100010111010",                                         "1011100010111010"                                         };  private String SNnumber="3102104000001";  private String EncodedString="";  private Dimension line=new Dimension(1,40);  //属性  private final static int DEFWIDTH=500;  private final static int DEFHEIGHT=80;  private final static boolean DEFTEXTINS=true;  private final static int DEFSIZE=1;  private final static Color DEFBACKCOLOR=Color.white;  private final static Color DEFFORECOLOR=Color.black;  private final static Font DEFFONT=new Font("Courier",0, 14);  private double wideToNarrowRatio=3;  private String intercharacterGap="0";  private double marginWidth,marginHeight;  private double labelLength;  private double labelHeight;  private String stringToEncode="";  private String filledStringToEncode="";  private String encodedString="";  private int narrowestDim=DEFSIZE;//  private boolean textInside=DEFTEXTINS;//  private int style=0;//  private int initialWidth=DEFWIDTH;//  private int initialHeight=DEFHEIGHT;//  private Color backColor=DEFBACKCOLOR;//  private Color foreColor=DEFFORECOLOR;//  private Font font=DEFFONT;//  private int textAlign=2;//  public Code39()  {    this("3OF9", DEFWIDTH, DEFHEIGHT, DEFSIZE, 0,                           DEFTEXTINS, DEFBACKCOLOR, DEFFORECOLOR, DEFFONT,                           2                           );  }  private Code39(String str, int iniWidth, int iniHeight,                                 int dimens, int Styl, boolean textIns,                                 Color backColor, Color foreColor,                                                 Font font, int textAlign                                                 ) {     this.stringToEncode=str;     this.narrowestDim=dimens;     this.initialWidth=iniWidth;     this.initialHeight=iniHeight;     this.textInside=textIns;     this.style=Styl;     this.backColor=backColor;     this.foreColor=foreColor;     this.font=font;     this.textAlign=textAlign;     Encode();   }  public synchronized void paint(Graphics g) {    super.paint(g);    FontMetrics metrics=g.getFontMetrics();    int ha=metrics.getAscent()-metrics.getDescent();    int hb=ha/2;    int hc=line.height;    int hd=line.width;    int he=metrics.getAscent()-metrics.getDescent();    int totalheight=ha+hb+hc+hd+he;    int wb=line.width*95;    int wc=line.width;    int totalwidth=wb+wc;    Dimension dim=new Dimension(totalwidth,totalheight);    this.setMinimumSize(dim);    int x=(this.getWidth())/4;    int y=(this.getHeight()-totalheight-20)/2;    drawCode39(g,x,y+ha+hb-10,hd+he/2-20);    g.drawString("*"+SNnumber+"*",x+52,y+totalheight);  }  private void drawCode39(Graphics g,int x,int y,int t) {    int x1=x;    int one=line.width;    int height=line.height;    String s=EncodedString;    int n=s.length();    for(int i=0;i<n;i++) {      if(s.charAt(i)=='1') {        g.fillRect(x1,y,one,height);      }      x1+=one;    }  }  public void setCode39(String s) {    if(s!=null && s.length()==13) {      boolean valid=true;      for(int i=0;i<13;i++) {        if(!Character.isDigit(s.charAt(i))) {          valid=false;          break;        }      }      if(valid) {        this.SNnumber=s;        this.repaint();      }    }    Encode();  }  public void clearBar()  {    this.setForeground(Color.white);  }  public void displayBar()  {    this.setForeground(Color.black);  }  public String getUpc() {    return this.SNnumber;  }  public void setLineDimension(Dimension dim) {    if(dim.width>0 && dim.height>0) {      this.line=new Dimension(dim.width,dim.height);      this.repaint();    }  }  public Dimension getLineDimension() {    return new Dimension(line.width,line.height);  }  public void setSize(int width, int height)  {    initialWidth=width;    initialHeight=height;    super.setSize( width, height);    repaint();  }  private void Encode()  {    for(int i=0;i<13;i++) {      EncodedString+=CODEA[SNnumber.charAt(i)-'0'];    }    EncodedString="1000101110111010"+EncodedString+"1000101110111010";    repaint();  }  private void stringValidate() throws IllegalArgumentException {  }  public void setFont(Font fnt) { font=fnt; repaint(); }  public Font getFont() { return font; }  public void setForeground(Color c) { foreColor=c;  repaint(); }  public Color getForeground() { return foreColor; }  public void setBackground(Color c) { backColor=c;  repaint(); }  public Color getBackground() { return backColor; }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -