Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/02/2011, 15:04
Avatar de valdo_kof
valdo_kof
 
Fecha de Ingreso: noviembre-2009
Ubicación: San Juan del Rio, Qro
Mensajes: 192
Antigüedad: 14 años, 5 meses
Puntos: 16
Respuesta: hacer paneles y hacerlos imagen

chuidiang
intente hacer lo q me recomendaste pero no pude e intente hacerlo de otra forma.

mira he echo esto hasta el momento con este codigo me guarda una imagen con las separaciones que necesito para una etiqueta pero no me guarda lo q le añado al panel

si cambas de JPanel a JFrame se puede ver lo que quiero por separado, la imagen con las diviciones q necesito para mi etiqueta y en pantalla arroja los datos como los necesito distribuidos

no se si me expliq pero ya ejecutado se ve

te dejo el codigo a ver si me puedes decir q estoy haciendo mal

Código Java:
Ver original
  1. import java.io.FileNotFoundException;
  2. import java.io.IOException;
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.geom.Rectangle2D;
  6. import java.awt.image.BufferedImage;
  7. import java.io.File;
  8. import java.io.FileOutputStream;
  9. import javax.imageio.ImageIO;
  10. import net.sourceforge.barbecue.Barcode;
  11. import net.sourceforge.barbecue.BarcodeException;
  12. import net.sourceforge.barbecue.BarcodeFactory;
  13. import net.sourceforge.barbecue.BarcodeImageHandler;
  14. import net.sourceforge.barbecue.output.OutputException;
  15.  
  16. public class Ventana extends JFrame        
  17.  {    
  18.      public Ventana() throws BarcodeException, FileNotFoundException, OutputException, IOException
  19.      {
  20.         super ();
  21.          this.setLayout(new GridBagLayout());
  22.          this.setSize(300, 295);
  23.          //this.setSize(1470, 1350);
  24.          this.setBackground(Color.white);
  25.          GridBagConstraints constraints = new GridBagConstraints();
  26.        Barcode barcode = BarcodeFactory.createCode39("N14U-93110-00",false);
  27. barcode.setDrawingText(false);
  28.  barcode.setBarHeight(45);
  29.  barcode.setBarWidth(1);
  30.  FileOutputStream fos = new FileOutputStream("c:/N14U-93110-00.jpeg");
  31.   BarcodeImageHandler.writeJPEG(barcode, fos);
  32.    ImageIcon icon = new ImageIcon("c:/N14U-93110-00.jpeg");
  33. Barcode barcode_q = BarcodeFactory.createCode39("Q8",false);
  34. barcode_q.setDrawingText(false);
  35.  barcode_q.setBarHeight(45);
  36.  barcode_q.setBarWidth(1);
  37.  FileOutputStream fos_q = new FileOutputStream("c:/q8.jpeg");
  38.   BarcodeImageHandler.writeJPEG(barcode_q, fos_q);
  39.    ImageIcon icon_q = new ImageIcon("c:/q8.jpeg");
  40.  
  41.    Barcode barcode_l = BarcodeFactory.createCode39("L1111",false);
  42. barcode_l.setDrawingText(false);
  43.  barcode_l.setBarHeight(45);
  44.  barcode_l.setBarWidth(1);
  45.  FileOutputStream fos_l= new FileOutputStream("c:/l1111.jpeg");
  46.  BarcodeImageHandler.writeJPEG(barcode_l, fos_l);
  47.  ImageIcon icon_l = new ImageIcon("c:/l1111.jpeg");
  48.  JLabel country=new JLabel("HARADA INDUSTRY OF AMERICA");
  49.  country.setFont(new java.awt.Font("Arial", 1, 10));
  50.  JLabel item=new JLabel("ITEM No.");
  51.  item.setFont(new java.awt.Font("Arial", 1, 8));
  52.  JLabel item_comp=new JLabel("(N)");
  53.  item_comp.setFont(new java.awt.Font("Arial", 1, 8));
  54.  JLabel item_no=new JLabel("14U-93110-00");
  55.  item_no.setFont(new java.awt.Font("Arial", 1, 12));
  56.  JLabel image=new JLabel();
  57.  image.setIcon(icon);
  58.  JLabel espacio=new JLabel(" ");
  59.  JLabel qty=new JLabel("8");
  60.  qty.setFont(new java.awt.Font("Arial", 1, 12));
  61.  JLabel Quantity=new JLabel("Quantity");
  62.  Quantity.setFont(new java.awt.Font("Arial", 1, 8));
  63.  JLabel q=new JLabel("(Q)");
  64.  q.setFont(new java.awt.Font("Arial", 1, 8));
  65.  JLabel image_q=new JLabel();
  66.  image_q.setIcon(icon_q);
  67.  JLabel l=new JLabel("1111");
  68.  l.setFont(new java.awt.Font("Arial", 1, 12));
  69.  JLabel lot=new JLabel("Lot No.");
  70.  lot.setFont(new java.awt.Font("Arial", 1, 8));
  71.  JLabel lo=new JLabel("(L)");
  72.  lo.setFont(new java.awt.Font("Arial", 1, 8));
  73.  JLabel image_l=new JLabel();
  74.  image_l.setIcon(icon_l);
  75.  JLabel c=new JLabel("28200 9E000");
  76.  c.setFont(new java.awt.Font("Arial", 1, 12));
  77.  JLabel cus=new JLabel("Customer No.");
  78.  cus.setFont(new java.awt.Font("Arial", 1, 8));
  79.  JLabel country2=new JLabel("ASSEMBLED IN MEXICO.");
  80.  country2.setFont(new java.awt.Font("Arial", 1, 10));
  81.  Rectangle2D.Double border = new Rectangle2D.Double(0, 0, 243.84, 243.84);
  82.  
  83.          constraints.gridx = 1;
  84.          constraints.gridy = 0;
  85.          constraints.gridwidth = 1;
  86.          constraints.gridheight = 1;
  87.         constraints.weightx=0;
  88.         constraints.weightx=0;
  89.          this.add (country, constraints);
  90.  
  91.          constraints.gridx = 0;
  92.          constraints.gridy = 1;
  93.          constraints.gridwidth = 1;
  94.          constraints.gridheight = 1;
  95.          this.add (item, constraints);
  96.  
  97.      constraints.gridx = 0;
  98.          constraints.gridy = 2;
  99.          constraints.gridwidth = 1;
  100.          constraints.gridheight = 1;
  101.          this.add (item_comp, constraints);
  102.  
  103.          constraints.gridx = 1;
  104.          constraints.gridy = 2;
  105.          constraints.gridwidth = 1;
  106.          constraints.gridheight = 1;
  107.          this.add (item_no, constraints);
  108.  
  109.      constraints.gridx = 1;
  110.          constraints.gridy = 3;
  111.          constraints.gridwidth = 1;
  112.          constraints.gridheight = 1;
  113.          this.add (image, constraints);
  114.  
  115.          constraints.gridx = 0;
  116.          constraints.gridy = 4;
  117.          constraints.gridwidth = 1;
  118.          constraints.gridheight = 1;
  119.          this.add (espacio, constraints);
  120.  
  121.          constraints.gridx = 0;
  122.          constraints.gridy = 5;
  123.          constraints.gridwidth = 1;
  124.          constraints.gridheight = 1;
  125.          this.add (Quantity, constraints);
  126.  
  127.          constraints.gridx = 0;
  128.          constraints.gridy = 6;
  129.          constraints.gridwidth = 1;
  130.          constraints.gridheight = 1;
  131.          this.add (q, constraints);
  132.  
  133.          constraints.gridx = 1;
  134.          constraints.gridy = 6;
  135.          constraints.gridwidth = 1;
  136.          constraints.gridheight = 1;
  137.          this.add (qty, constraints);
  138.  
  139.          constraints.gridx = 1;
  140.          constraints.gridy = 7;
  141.          constraints.gridwidth = 1;
  142.          constraints.gridheight = 1;
  143.          this.add (image_q, constraints);
  144.  
  145.          constraints.gridx = 0;
  146.          constraints.gridy = 8;
  147.          constraints.gridwidth = 1;
  148.          constraints.gridheight = 1;
  149.          this.add (espacio, constraints);
  150.  
  151.          constraints.gridx = 0;
  152.          constraints.gridy = 9;
  153.          constraints.gridwidth = 1;
  154.          constraints.gridheight = 1;
  155.          this.add (lot, constraints);
  156.  
  157.          constraints.gridx = 0;
  158.          constraints.gridy = 10;
  159.          constraints.gridwidth = 1;
  160.          constraints.gridheight = 1;
  161.          this.add (lo, constraints);
  162.  
  163.          constraints.gridx = 1;
  164.          constraints.gridy = 10;
  165.          constraints.gridwidth = 1;
  166.          constraints.gridheight = 1;
  167.          this.add (l, constraints);
  168.  
  169.          constraints.gridx = 1;
  170.          constraints.gridy = 11;
  171.          constraints.gridwidth = 1;
  172.          constraints.gridheight = 1;
  173.          this.add (image_l, constraints);
  174.  
  175.          constraints.gridx = 0;
  176.          constraints.gridy = 12;
  177.          constraints.gridwidth = 1;
  178.          constraints.gridheight = 1;
  179.          this.add (espacio, constraints);
  180.  
  181.          constraints.gridx = 0;
  182.          constraints.gridy = 13;
  183.          constraints.gridwidth = 1;
  184.          constraints.gridheight = 1;
  185.          this.add (cus, constraints);
  186.  
  187.          constraints.gridx = 1;
  188.          constraints.gridy = 13;
  189.          constraints.gridwidth = 1;
  190.          constraints.gridheight = 1;
  191.          this.add (c, constraints);
  192.  
  193.          constraints.gridx = 1;
  194.          constraints.gridy = 14;
  195.          constraints.gridwidth = 1;
  196.          constraints.gridheight = 1;
  197.          this.add (country2, constraints);
  198.          
  199.           BufferedImage imagen = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_RGB);
  200.          Graphics g = imagen.getGraphics();
  201.          g.drawRect(1, 1, 296, 108);
  202.          g.drawRect(1,109, 296, 72);
  203.           g.drawRect(1,181, 296, 72);
  204.           g.drawRect(1,253, 296, 38);
  205.           g.setXORMode(Color.black);
  206.           this.paint(g);
  207.      
  208.           ImageIO.write(imagen,"jpg",new File("c:/prueba.jpg"));
  209.           //ImageIO.write(imagen,"jpg",new File("c:/prueba.jpg"));
  210.      }
  211.      public static void main(String args[]) throws BarcodeException, FileNotFoundException, OutputException, IOException{
  212.      Ventana obj= new Ventana();
  213.      obj.setVisible(true);
  214.      }
  215. }