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

📄 printcard..java~1~

📁 会议名片管理程序 3/9条形码生成
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
package mymanager.print;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;public class PrintCard extends Canvas implements  ActionListener, Printable,ImageObserver{  // CODE 39 CHARACTERS  private static String alphabet3of9="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";  private static String coded3of9Char[]={         /* 0 */ "000110100", /* 1 */ "100100001", /* 2 */ "001100001", /* 3 */ "101100000",         /* 4 */ "000110001", /* 5 */ "100110000", /* 6 */ "001110000", /* 7 */ "000100101",         /* 8 */ "100100100", /* 9 */ "001100100", /* A */ "100001001", /* B */ "001001001",         /* C */ "101001000", /* D */ "000011001", /* E */ "100011000", /* F */ "001011000",         /* G */ "000001101", /* H */ "100001100", /* I */ "001001100", /* J */ "000011100",         /* K */ "100000011", /* L */ "001000011", /* M */ "101000010", /* N */ "000010011",         /* O */ "100010010", /* P */ "001010010", /* Q */ "000000111", /* R */ "100000110",         /* S */ "001000110", /* T */ "000010110", /* U */ "110000001", /* V */ "011000001",         /* W */ "111000000", /* X */ "010010001", /* Y */ "110010000", /* Z */ "011010000",         /* - */ "010000101", /* . */ "110000100", /*SPACE*/"011000100",/* $ */ "010101000",         /* / */ "010100010", /* + */ "010001010", /* % */ "000101010", /* * */ "010010100" };     /**     * Costant for variant of the code.     * @see #CODE3OF9CHK     * @see #CODE3OF9     * @see #setStyle     * @see #getStyle     */  public final static int CODE3OF9=0, CODE3OF9CHK=1;    /**     * Costant for size of the narrowest bar.     * @see #SMALL     * @see #MEDIUM     * @see #LARGE     * @see #setDimension     * @see #getDimension     */  public final static int SMALL=1,MEDIUM=2,LARGE=3;    /**     * Costant for text alignment.     * @see #BASELINE     * @see #MIDDLELINE     * @see #TOPLINE     * @see #setTextAlign     * @see #getTextAlign     */  public final static int BASELINE=0,MIDDLELINE=1,TOPLINE=2;  // default values  private final static int DEFWIDTH=500;  private final static int DEFHEIGHT=250;  private final static boolean DEFTEXTINS=true;  private final static int DEFSIZE=SMALL;  private final static Color DEFBACKCOLOR=Color.white;  private final static Color DEFFORECOLOR=Color.black;  private final static Font DEFFONT=new Font("Courier",0, DEFWIDTH/25);           // private members  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=CODE3OF9;  private int initialWidth=DEFWIDTH;  private int initialHeight=DEFHEIGHT;  private Color backColor=DEFBACKCOLOR;  private Color foreColor=DEFFORECOLOR;  private Font font=DEFFONT;  private int textAlign=TOPLINE;    // Constructors    /**     * Constructs a Barcode object with an empty string and the following defaults:<br>     * size 100x50;<br>     * label inside;<br>     * small rendering;<br>     * black on white color;<br>     * Courier,12 font;     */  private String stringName="";  private String stringPosition="";  private String stringCompany="";  public PrintCard(String sName, String sPosition, String sCompany)  {    this("3OF9", DEFWIDTH, DEFHEIGHT, DEFSIZE, CODE3OF9,                           DEFTEXTINS, DEFBACKCOLOR, DEFFORECOLOR, DEFFONT,                           TOPLINE,sName,sPosition,sCompany);  }  private PrintCard(String str, int iniWidth, int iniHeight,                                  int dimens, int Styl, boolean textIns,                                  Color backColor, Color foreColor,                                                  Font font, int textAlign,String sName,                                                  String sPosition ,  String sCompany )  {    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;    this.stringName=sName;    this.stringPosition=sPosition;    this.stringCompany=sCompany;    Encode();  }  public int print(Graphics g, PageFormat pf, int page) throws PrinterException  {    Graphics2D g2 = (Graphics2D)g;    g2.setPaint(Color.black); //设置打印颜色为黑色    if (page >0) //当打印页号大于需要打印的总页数时,打印工作结束      return Printable.NO_SUCH_PAGE;      //	repaint();      //setSize(500,250);    Rectangle rect=this.getBounds();    double cwidth=getSize().width;    double cheight=getSize().height;    double scalex=pf.getImageableWidth()/cwidth;    double scaley=pf.getImageableHeight()/cheight;    double scale=Math.min( scalex, scaley);    g2.translate(pf.getImageableX(), pf.getImageableY());//转换坐标,确定打印边界    g2.scale( scale, scale);    g2.translate(-rect.x,-rect.y);    paint(g2);//打印当前页文本      //this.getGraphics();    return Printable.PAGE_EXISTS; //存在打印页时,继续打印工作  }  public void actionPerformed(ActionEvent evt)  {}   /**     * Returns the mininimum size of this component.     * @see #getPreferredSize     */  public Dimension getMinimumSize()  {    return minimumSize();  }   /**     * Returns the minimum size of this component.     * @see #preferredSize     */  public Dimension minimumSize()  {    Dimension minSize = new Dimension(initialWidth,initialHeight);    return minSize;  }   /**     * Returns the preferred size of this component.     * @see #getMinimumSize     */  public Dimension getPreferredSize() { return preferredSize();  }  /**     * @deprecated As of JDK version 1.1,     * replaced by getPreferredSize().     */  public Dimension preferredSize() { return minimumSize(); }           /**     * Resizes the Component to the specified width and height.     * @param width the width of the component     * @param height the height of the component     */  public void setSize(int width, int height)  {    initialWidth=width; initialHeight=height;    super.setSize( width, height); repaint();  }   //Resizes the Component to the default width and height.  public void setDefaultSize()  {    initialWidth=DEFWIDTH; initialHeight=DEFHEIGHT;    super.setSize( DEFWIDTH, DEFHEIGHT); repaint();  }           /**     * Resizes the Component to the specified dimension.     * @param d the dimension of the component     */  public void setSize(Dimension d)  {    initialWidth=d.width; initialHeight=d.height;    super.setSize(d.width,10*d.height); repaint();  }           /**     * Returns the parameter String of this Component.     */  protected String paramString()  {    String str = filledStringToEncode + "," + initialWidth + "x" + initialHeight;    return str;  }    /**     * Returns the String representation of this Component's values.     */  public String toString() { 	return getClass().getName() + "[" + paramString() + "]";  }   /**     * Return the minimum dimension needed to successfully display a code of string str.     * Use it to resize the component using method  resize(Dimension d)     * @param str the sting to encode     * @return the minimum dimension     */  public Dimension requestedMinimunSize(String str)  {    int width=str.length()*16*this.narrowestDim+31*this.narrowestDim;    if ( this.style==CODE3OF9CHK )      width+=16*this.narrowestDim;    int height=Math.max((int)(.15*width),35);    return new Dimension(width,height);  }   /**     * Sets the string encoded in the Barcode.     * @param str the string to encode     * @exception IllegalArgumentException If an improper string was given.     * @see #getString     */  public void setString(String str) throws IllegalArgumentException  {    stringToEncode=str;    stringValidate();    Encode();  }   /**     * Gets the string encoded in the Barcode.     * @return the encoded string     * @see #setString     */  public String getString() { return stringToEncode;   }   /**     * Sets the dimension of the narrowest bar. Values allowed are SMALL, MEDIUM and LARGE     * @param dim the dimension     * @see #SMALL     * @see #MEDIUM     * @see #LARGE     * @see #getDimension     */  public void setDimension(int dim)  {    switch (dim)    {      case SMALL:      case MEDIUM:      case LARGE:            narrowestDim=dim;            repaint();            return;    }    narrowestDim=DEFSIZE;    repaint();  }   /**     * Gets the dimension of the narrowest bar.     * @return the dim of the bar     * @see #SMALL     * @see #MEDIUM     * @see #LARGE     * @see #setDimension     */  public int getDimension() { return narrowestDim; }

⌨️ 快捷键说明

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