[java-list] Re: RES: [JavaC] código de barras
Marcus, Segue a classe BarCode2of5: package barcode; import com.sun.image.codec.jpeg.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; /** * A class that produces a Barcode component. */ public class BarCode2of5 extends Canvas { private static String alphabet2of5 = 0123456789; private static String coded2of5Char[] = {00110, 10001, 01001, 11000, 00101, 10100, 01100, 00011, 10010, 01010}; /** Constant for variant of the code. */ public static final int CODE2OF5 = 0; /** Constant for variant of the code. */ public static final int CODE2OF5CHK = 1; /** Constant for size of the narrowest bar. */ public static final int SMALL = 1; /** Costant for size of the narrowest bar. */ public static final int MEDIUM = 2; /** Constant for size of the narrowest bar. */ public static final int LARGE = 3; /** Constant for text alignment. */ public static final int BASELINE = 0; /** Constant for text alignment. */ public static final int MIDDLELINE = 1; /** Constant for text alignment. */ public static final int TOPLINE = 2; private static final int DEFWIDTH = 50; private static final int DEFHEIGHT = 25; private static final boolean DEFTEXTINS = true; private static final int DEFSIZE = 1; private static final Color DEFBACKCOLOR; private static final Color DEFFORECOLOR; private static final Font DEFFONT = new Font(Courier, 0, 12); private String strStartPattern; private String strStopPattern; private double wideToNarrowRatio; private double marginWidth; private double marginHeight; private double labelLength; private double labelHeight; private String stringToEncode; private String filledStringToEncode; private String encodedString; private int narrowestDim; private boolean textInside; private int style; private int initialWidth; private int initialHeight; private Color backColor; private Color foreColor; private Font font; private int textAlign; static { DEFBACKCOLOR = Color.white; DEFFORECOLOR = Color.black; } /** * PConstructs a Barcode object with an empty string and the following defaults: * BRsize 100x50; * BRlabel inside; * BRsmall rendering; * BRblack on white color; * BRCourier,12 font; */ public BarCode2of5() { this(012345, 50, 25, 1, 0, true, DEFBACKCOLOR, DEFFORECOLOR, DEFFONT, 2); } private BarCode2of5(String s, int i, int j, int k, int l, boolean flag, Color color, Color color1, Font font1, int i1) { strStartPattern = ; strStopPattern = 100; wideToNarrowRatio = 3D; stringToEncode = ; filledStringToEncode = ; encodedString = ; narrowestDim = 1; textInside = true; style = 0; initialWidth = 50; initialHeight = 25; backColor = DEFBACKCOLOR; foreColor = DEFFORECOLOR; font = DEFFONT; textAlign = 1; stringToEncode = s; narrowestDim = k; initialWidth = i; initialHeight = j; textInside = flag; style = l; backColor = color; foreColor = color1; font = font1; textAlign = i1; Encode(); } / // Public methods / /** * Returns the mininimum size of this component. */ public Dimension getMinimumSize() { return minimumSize(); } /** * Returns the minimum size of this component. */ public Dimension minimumSize() { Dimension dimension = new Dimension(initialWidth, initialHeight); return dimension; } public Dimension getPreferredSize() { return preferredSize(); } public Dimension preferredSize() { return minimumSize(); } public void setSize(int i, int j) { initialWidth = i; initialHeight = j; super.setSize(i, j); repaint(); } public void setSize(Dimension dimension) { initialWidth = dimension.width; initialHeight = dimension.height; super.setSize(dimension.width, dimension.height); repaint(); } public String toString() { return getClass().getName() + [ + paramString() + ]; } public Dimension requestedMinimunSize(String s) { int i = s.length() * 16 * narrowestDim + 31 * narrowestDim; if(style == 1) i += 16 * narrowestDim; int j = Math.max((int)(0.14999D * (double)i), 35); return new Dimension(i, j); } public void setString(String s) throws IllegalArgumentException { stringToEncode = s; stringValidate(); Encode(); } public String getString() { return stringToEncode; } public void setDimension(int i) { switch(i) { case 1: // '\001' case 2: // '\002' case 3: // '\003' narrowestDim = i; repaint(); return; } narrowestDim = 1; repaint(); }
Re: [java-list] Re: RES: [JavaC] código de barras
Onde posso encontrar a classe BarCode2of5 ? - Original Message - From: Nilo Garcia Silveira [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, January 11, 2002 10:48 AM Subject: [java-list] Re: RES: [JavaC] código de barras Oi Reinaldo, Para gerar para arquivo é o seguinte: Crie uma classe Java que pegue a string do código de barra e então você cria um objeto BarCode2of5: public class Teste { public static void main() { FileOutputStream fos = new FileOutputStream(C:\\diretorio\\barra.jpg); ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(); barCode = new BarCode3of9(); try{ barCode.createBarCode(imageBuffer,barCodeString); imageBuffer.writeTo(fos); /* ou acho que isso tb deve funcionar... fos.write(imageBuffer.toByteArray()); */ fos.close(); } catch (IOException ioex) { ioex.printStackTrace(); } } } Reinaldo Yoshio Simizu wrote: valeu kra, descobri o problema, estava compilando com o 1.4 e na verdade o tomcat tava apontando pro diretório do 1.3 foi burrice minha.Ah, ele está imprimindo o código de barras no browser, vc sabe como fazer para gerar um arquivo em algum diretório?? É só mexer no main da classe BarCode2of5?? []s reinaldo - Original Message - From: Nilo Garcia Silveira [EMAIL PROTECTED] To: Reinaldo Yoshio Simizu [EMAIL PROTECTED] Sent: Thursday, January 10, 2002 4:18 PM Subject: Re: RES: [JavaC] código de barras Reinaldo, Não sei se vc percebeu, mas as classes possuem um package. Eu não sei como funciona o Tomcat mas, acho que as classes devem estar em algum diretório do CLASSPATH e, além disso, respeitar o PACKAGE. Então, por exemplo: Se o diretório C:\TOMCAT\CLASSES está no CLASSPATH, então vc deveria criar um subdiretório -- barcode e, então copiar as classes lá.. Bom, isso é um chute, nunca mexi com TOMCAT mas acho que isso faz lógica -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 Reinaldo Yoshio Simizu wrote: Coloquei os arquivos BarCodeBean.class e .java e BarCode2of5.class e .java no mesmo diretório do .jsp (showBarCode) e está dando erro de compilação, que o jsp não reconhece BarCodeBean. Vc imagina o q seja? Será q montei esses arquivos . class de maneira incorreta?! valeu! reinaldo - Original Message - From: Nilo Garcia Silveira [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, January 10, 2002 2:58 PM Subject: Re: RES: [JavaC] código de barras Reinaldo, Lá vai de novo, showBarCode.jsp -- %@ page contentType=image/jpeg% jsp:useBean class=barcode.BarCodeBean id=barCodeBean scope=request / jsp:setProperty name=barCodeBean property=*/ % // System.out.println([showBarCode.jsp] Gerador de Código de Barras inicializado !!); barCodeBean.initialize(application,session, request,response,out); barCodeBean.renderBarCode(); // System.out.println([showBarCode.jsp] Gerador de Código de Barras finalizado !!); % -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 Para sair do grupo, mande mail p/: [EMAIL PROTECTED] Seu uso do Yahoo! Grupos é sujeito às regras descritas em: http://br.yahoo.com/info/utos.html -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 -- LISTA SOUJAVA http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm para sair da lista: envie email para [EMAIL PROTECTED] - -- LISTA SOUJAVA http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm para sair da lista: envie email para [EMAIL PROTECTED] -
[java-list] Re: RES: [JavaC] código de barras
Oi Reinaldo, Para gerar para arquivo é o seguinte: Crie uma classe Java que pegue a string do código de barra e então você cria um objeto BarCode2of5: public class Teste { public static void main() { FileOutputStream fos = new FileOutputStream(C:\\diretorio\\barra.jpg); ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(); barCode = new BarCode3of9(); try{ barCode.createBarCode(imageBuffer,barCodeString); imageBuffer.writeTo(fos); /* ou acho que isso tb deve funcionar... fos.write(imageBuffer.toByteArray()); */ fos.close(); } catch (IOException ioex) { ioex.printStackTrace(); } } } Reinaldo Yoshio Simizu wrote: valeu kra, descobri o problema, estava compilando com o 1.4 e na verdade o tomcat tava apontando pro diretório do 1.3 foi burrice minha.Ah, ele está imprimindo o código de barras no browser, vc sabe como fazer para gerar um arquivo em algum diretório?? É só mexer no main da classe BarCode2of5?? []s reinaldo - Original Message - From: Nilo Garcia Silveira [EMAIL PROTECTED] To: Reinaldo Yoshio Simizu [EMAIL PROTECTED] Sent: Thursday, January 10, 2002 4:18 PM Subject: Re: RES: [JavaC] código de barras Reinaldo, Não sei se vc percebeu, mas as classes possuem um package. Eu não sei como funciona o Tomcat mas, acho que as classes devem estar em algum diretório do CLASSPATH e, além disso, respeitar o PACKAGE. Então, por exemplo: Se o diretório C:\TOMCAT\CLASSES está no CLASSPATH, então vc deveria criar um subdiretório -- barcode e, então copiar as classes lá.. Bom, isso é um chute, nunca mexi com TOMCAT mas acho que isso faz lógica -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 Reinaldo Yoshio Simizu wrote: Coloquei os arquivos BarCodeBean.class e .java e BarCode2of5.class e .java no mesmo diretório do .jsp (showBarCode) e está dando erro de compilação, que o jsp não reconhece BarCodeBean. Vc imagina o q seja? Será q montei esses arquivos . class de maneira incorreta?! valeu! reinaldo - Original Message - From: Nilo Garcia Silveira [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, January 10, 2002 2:58 PM Subject: Re: RES: [JavaC] código de barras Reinaldo, Lá vai de novo, showBarCode.jsp -- %@ page contentType=image/jpeg% jsp:useBean class=barcode.BarCodeBean id=barCodeBean scope=request / jsp:setProperty name=barCodeBean property=*/ % // System.out.println([showBarCode.jsp] Gerador de Código de Barras inicializado !!); barCodeBean.initialize(application,session, request,response,out); barCodeBean.renderBarCode(); // System.out.println([showBarCode.jsp] Gerador de Código de Barras finalizado !!); % -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 Para sair do grupo, mande mail p/: [EMAIL PROTECTED] Seu uso do Yahoo! Grupos é sujeito às regras descritas em: http://br.yahoo.com/info/utos.html -- Nilo Garcia Silveira Estagiário Visual Systems Informatica Ltda. Oracle Partner Program http://www.visualsystems.com.br Tel: (17) 2124425 R. 31 -- LISTA SOUJAVA http://www.soujava.org.br - Sociedade de Usuários Java da Sucesu-SP dúvidas mais comuns: http://www.soujava.org.br/faq.htm regras da lista: http://www.soujava.org.br/regras.htm para sair da lista: envie email para [EMAIL PROTECTED] -