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

📄 printcard.java~51~

📁 会议名片管理程序 3/9条形码生成
💻 JAVA~51~
📖 第 1 页 / 共 2 页
字号:
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 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=260;  private final static boolean DEFTEXTINS=true;  private final static int DEFSIZE=SMALL;//=1;  private final static Color DEFBACKCOLOR=Color.white;//±\u00B3\u00BE°\u00C9\u00AB°×\u00C9\u00AB  private final static Color DEFFORECOLOR=Color.black;//\u00C7°\u00BE°\u00C9\u00AB\u00BA\u00DA\u00C9\u00AB  private final static Font DEFFONT=new Font("Courier",0, DEFWIDTH/25);//20                                                               //=20           // private members  private double wideToNarrowRatio=3;//\u00BFí\u00CC\u00F5\u00D5\u00AD\u00CC\u00F5\u00BFí\u00B6\u00C8±\u00C8\u00C0\u00FD\u00CE\u00AA3:1  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;//=1  private boolean textInside=DEFTEXTINS;//true  private int style=CODE3OF9;//=0  private int initialWidth=DEFWIDTH;//500  private int initialHeight=DEFHEIGHT;//250  private Color backColor=DEFBACKCOLOR;//°×\u00C9\u00AB  private Color foreColor=DEFFORECOLOR;//\u00BA\u00DA\u00C9\u00AB  private Font font=DEFFONT;//\u00C4\u00AC\u00C8\u00CF·\u00E7\u00B8\u00F1,\u00B4ó\u00D0\u00A120.Courier  private int textAlign=TOPLINE;//=2  // 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=500;     System.out.println("cwidth="+cwidth);     double cheight=250;     System.out.println("cheight="+cheight);     double scalex=pf.getImageableWidth()/cwidth;     System.out.println("scalex="+scalex);     double scaley=pf.getImageableHeight()/cheight;     System.out.println("scaley="+scaley);     double scale=Math.min( scalex, scaley);     System.out.println("scale="+scale);     g2.translate(pf.getImageableX(), pf.getImageableY());//×\u00AA\u00BB\u00BB×\u00F8±ê\u00A3\u00AC\u00C8·\u00B6¨\u00B4ò\u00D3\u00A1±\u00DF\u00BD\u00E7     g2.scale( scale, scale);     g2.translate(-rect.x,-rect.y);     paint(g2);//\u00B4ò\u00D3\u00A1\u00B5±\u00C7°\u00D2\u00B3\u00CE\u00C4±\u00BE    //this.getGraphics();    return Printable.PAGE_EXISTS; //\u00B4\u00E6\u00D4\u00DA\u00B4ò\u00D3\u00A1\u00D2\u00B3\u00CA±\u00A3\u00AC\u00BC\u00CC\u00D0\u00F8\u00B4ò\u00D3\u00A1\u00B9¤×÷  }  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;

⌨️ 快捷键说明

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