Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/01/2011, 12:06
Avatar de valdo_kof
valdo_kof
 
Fecha de Ingreso: noviembre-2009
Ubicación: San Juan del Rio, Qro
Mensajes: 192
Antigüedad: 15 años, 5 meses
Puntos: 16
impresion de etiquetas con codigo de barras

tengo el siguiente codio q me manda a imprimir una etiqueta pequueña con un simple valor, la pregunta es como puedo hacer que me dibuje dos rectangulos uno enseguida del otro hacia abajo ejemplo
_______
| |
| |
|______|
_______
| |
| |
|______|

y poderle agregar en vez del valor fijo un codigo de barras

Código Java:
Ver original
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.FontMetrics;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.geom.Rectangle2D;
  7. import java.awt.print.Book;
  8. import java.awt.print.PageFormat;
  9. import java.awt.print.Printable;
  10. import java.awt.print.PrinterJob;
  11.  
  12. public class JavaWorldPrintExample3 {
  13.  public static void main(String[] args) {
  14.     JavaWorldPrintExample3 example3 = new JavaWorldPrintExample3();
  15.     System.exit(0);
  16.   }
  17.  private final static int POINTS_PER_INCH = 72;
  18.  public JavaWorldPrintExample3() {
  19.   PrinterJob printJob = PrinterJob.getPrinterJob();
  20.   Book book = new Book();
  21.   book.append(new IntroPage(), printJob.defaultPage());
  22.     printJob.setPageable(book);
  23.     if (printJob.printDialog()) {
  24.       try {
  25.         printJob.print();
  26.       } catch (Exception PrintException) {
  27.         PrintException.printStackTrace();
  28.       }
  29.     }
  30.   }
  31.   private class IntroPage implements Printable {
  32.     public int print(Graphics g, PageFormat pageFormat, int page) {
  33.     Graphics2D g2d = (Graphics2D) g;
  34.     Graphics2D g2d2 = (Graphics2D) g;
  35.      g2d.translate(pageFormat.getImageableX(), pageFormat
  36.           .getImageableY());
  37.  g2d.setPaint(Color.black);
  38.  Rectangle2D.Double border = new Rectangle2D.Double(0, 0, 68, 39);
  39.  Rectangle2D.Double border2 = new Rectangle2D.Double(69, 69, 68, 39);
  40.       g2d.draw(border);
  41.       g2d2.draw(border2);
  42.       String titleText = "9001";
  43.       Font titleFont = new Font("helvetica", Font.BOLD, 14);
  44.       g2d.setFont(titleFont);
  45.        String titleText2 = "9001";
  46.       Font titleFont2 = new Font("helvetica", Font.BOLD, 14);
  47.         g2d2.setFont(titleFont2);
  48.  FontMetrics fontMetrics = g2d.getFontMetrics();
  49.  FontMetrics fontMetrics2 = g2d2.getFontMetrics();
  50.       double titleX = (68 / 2)-(39 / 2);
  51.       double valor=POINTS_PER_INCH/24.5;
  52.       double val=valor*14;
  53.       double titleY = val/2;
  54.       double titleX2 = (68 / 2)-(39 / 2);
  55.       double valor2=POINTS_PER_INCH/24.5;
  56.       double val2=valor2*14;
  57.       double titleY2 = val2/2;
  58.       g2d.drawString(titleText, (int) titleX, (int) titleY);
  59.       g2d2.drawString(titleText2, (int) titleX2, (int) titleY2);
  60.       return (PAGE_EXISTS);
  61.    }
  62.   }  
  63. }

si alguien me pudiera ayudar gracias