5

I am making an application to generate barcodes, but it does not give me the barcode: the application returns the text that I have provided. My code is:

Code39 code39=new Code39();
String outputStr=code39.encode("12345678", 1);
String humanTextStr=code39.getHumanText();
jLabel1.setText(outputStr);
jLabel1.setFont(new java.awt.Font("CCode39_S3",java.awt.Font.PLAIN,24));

Please can anyone tell me why this happens?

Chan
  • 2,601
  • 6
  • 28
  • 45
Jayashri
  • 366
  • 4
  • 13
  • 25

2 Answers2

6

Your application is returning a text because you have told it to get the text not the bar-code.

Try the following code:

a=jTextField24.getText();      
Code39 barcode=new Code39();      
barcode.setData(a);      
ImageIcon icon = new ImageIcon(barcode.drawBarcode());          
jLabel34.setIcon(icon);
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
Nitesh Verma
  • 1,795
  • 4
  • 27
  • 46
2

Try using open source libraries for generating barcodes in java. For e.g., iText or http://barbecue.sourceforge.net/

Please refer to this link as well BarCode Image Generator in Java

Hope it helps.

Community
  • 1
  • 1
krishnakumarp
  • 8,967
  • 3
  • 49
  • 55