如何使用烧烤库在java中创建多个条形码?

如何使用烧烤库在java中创建多个条形码?,java,netbeans,barcode,Java,Netbeans,Barcode,我想用java生成多个java条形码。 场景如下所示: 我有一个名为copies的文本字段,我想使用烧烤库并根据给定的数字生成条形码, uy 因此,如果我在文本字段中输入3,它将生成3个数字递增的条形码。对于三个条形码,数字将递增(例如,1、2、3) 有人能帮我吗?非常感谢你的帮助 以下是我生成单个条形码的代码: new File("C:\\Generated Barcodes").mkdir(); new File("D:\\Back-Up Generated Barcodes"

我想用java生成多个java条形码。 场景如下所示:

我有一个名为copies的文本字段,我想使用烧烤库并根据给定的数字生成条形码, uy 因此,如果我在文本字段中输入3,它将生成3个数字递增的条形码。对于三个条形码,数字将递增(例如,1、2、3)

有人能帮我吗?非常感谢你的帮助

以下是我生成单个条形码的代码:

new File("C:\\Generated Barcodes").mkdir();
       new File("D:\\Back-Up Generated Barcodes").mkdir();

    //Get 128B Barcode instance from the Factory
    Barcode barcode = null;

        try {
            barcode = BarcodeFactory.createCode128B(res.getText());

        } catch (BarcodeException ex) {
            Logger.getLogger(Barcode_IT.class.getName()).log(Level.SEVERE, null, ex);
        }
    barcode.setBarHeight(40);
    barcode.setBarWidth(2);

           generate2.setEnabled(false);
             save.setEnabled(true);
             Edit.setEnabled(true);


             File imgFile = new File("C://Generated Barcodes//"+res2.getText()+"_"+res.getText()+".png");

        try {
            //Write the bar code to PNG file
            BarcodeImageHandler.savePNG(barcode, imgFile);
        } catch (OutputException ex) {
            Logger.getLogger(Barcode_IT.class.getName()).log(Level.SEVERE, null, ex);
        }
              ImageIcon imgThisImg = new ImageIcon("C://Generated Barcodes//"+res2.getText()+"_"+res.getText()+".png");
            lres.setIcon(imgThisImg);
            file.setText(res2.getText()+"_"+res.getText()+".png");


    }

        }catch(Exception e){
           JOptionPane.showMessageDialog(Jframe, "Something Went Wrong!",
        "Inane warning", JOptionPane.ERROR_MESSAGE);

         }

你知道循环吗?使用循环生成多个条形码。 像这样

//Get 128B Barcode instance from the Factory
        Barcode barcode = null;
        int code = Integer.parseInt(res.getText());

        for (int i = 1; i <= code; i++) {
            try {
                barcode = BarcodeFactory.createCode128B(i + "");
            } catch (BarcodeException ex) {
                Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
            barcode.setBarHeight(40);
            barcode.setBarWidth(2);

            File imgFile = new File("C://Generated Barcodes//" + res2.getText() + "_" + i + ".png");
            System.out.println(code);

            try {
                //Write the bar code to PNG file
                BarcodeImageHandler.savePNG(barcode, imgFile);
            } catch (OutputException ex) {
                ex.printStackTrace();
            }
            ImageIcon imgThisImg = new ImageIcon("C://Generated Barcodes//" + res2.getText() + "_" + i + ".png");
            lres.setIcon(imgThisImg);
        }
//从工厂获取128B条形码实例
条码=空;
int code=Integer.parseInt(res.getText());

对于(int i=1;i生成条形码或递增数字有什么问题?看这一个,先生,我已经尝试了那一个,但是它确实起作用了,我想发生的是,我想根据给定的副本数生成多个条形码。它起作用了,先生,但是,我想生成多个条形码,而不是生成一个barcodeyes发布它…如果你在文本字段中输入5,你的预期输出是什么?我已经用如何生成单个条形码的代码编辑了我的帖子顺便问一下,先生,如何显示它?@Newbieu应该这么想。你有多个图像和一个标签。在这个代码中,它将生成一个图像,然后将其设置为标签。这种情况只会发生多次你看到最后一张图片,但他们已经保存为pngsit,实际上它对我不起作用…?这张图片发生了什么,先生?这是为了保存你想要的图片