我需要在文本框中输入特定数量时生成条形码。但似乎可以使用我所制作的代码。任何帮助将不胜感激。
import com.aspose.barcode.BarCodeBuilder;
import com.aspose.barcode.Symbology;
import com.aspose.words.Document;
import com.aspose.words.DocumentBuilder;
JButton btnCreate = new JButton("Create Barcode");
btnCreate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String strBaseFolder = "C:\\users\\ronjonathan\\desktop\\barcode\\";
try
{
// Generate barcode image
BarCodeBuilder builder = new BarCodeBuilder();
builder.setSymbologyType(Symbology.Code128);
for(int i = 1;i <= Integer.parseInt(txtBarcode.getText()); i++){
builder.setCodeText(Integer.toString(i));
String strBarCodeImageSave = "img.jpg"+ i;
builder.save(strBaseFolder + strBarCodeImageSave);
答案 0 :(得分:4)
每次运行此代码时,都会在同一个文件上写下&#34; img.jpg&#34;。尝试更改
String strBarCodeImageSave = "img.jpg";
到
String strBarCodeImageSave = txtBarcode.getText() + ".jpg";