Saboor880 9 Junior Poster

Hi developers! I have made a POS software. I have added the functionality of "priniting to Thermal printer" and "barcodes". Firstly I added the functionality of Reciept printing which worked perfectly. Then I added the functionality of barcode scanning. As you know barcode reader device automatically scans the barcode and write the barcode in Text field or excel sheet. But in the sales screen , all the field of item/product should be populated from database When barcode is scanned. I implemented an interface(I get this code form internet) in the my Sales Screen Constructor. It workded perfectly for me, but after adding this interface, my Printing functionality malfunctioned.i-e after sending Print command to the Printer, Printer just waits and does not print any thing and the Printer status remains constant i-e"Printing".

But if I remove the Barcode scanning interface, The Printer works fine again, I want to know that why Implementation of Barcode scanning Interface, printer stops working? I think that the barcode scanning Interface (which i implemented) keeps a port busy , But I am not sure which port and why?

I am also giving the code of implementation of barcode scanning.

private AWTEventListener barcodeListener=null;

//now implementing the interface.
barcodeListener= (new BarcodeAwareAWTEventListener(new BarcodeCapturedListener() {
            public void barcodeCaptured(String barcodeString) {
                   char[] strArray;
                 // JOptionPane.showMessageDialog(Sale.this, "barcode captured: "+barcodeString);
                 strArray = barcodeString.toCharArray(); 

        StringBuffer stringBuffer = new StringBuffer(); 

                 for (int i = 0; i < strArray.length; i++) {  
            if ((Integer.valueOf(strArray[i])!=32)) {  

                String noSpaceStr = stringBuffer.toString();  

               char[] strArray2 = noSpaceStr.toCharArray(); 
              StringBuffer stringBuffer2 = new StringBuffer();
              for (int i = 0; i < strArray2.length; i++) {  
            if ((Integer.valueOf(strArray2[i])!=8)) {  
              String noSpaceStr2 = stringBuffer2.toString();
             // JOptionPane.showMessageDialog(Sale.this, "barcode found: "+noSpaceStr2);

                try {
                    String itmName = obj.selectSingleItemByProductCode(noSpaceStr2);
                 //   JOptionPane.showMessageDialog(Sale.this, "product corresponding to code: "+itmName);
                       JOptionPane.showMessageDialog(Sale.this, "No Product found for this barcode.\n"
                               + "Try again to scan the barcode on Product.\n               OR\n check that whether you "
                               + "have entered the product\nwith this barcode in the inventory or not","Error",JOptionPane.ERROR_MESSAGE);
                          // populating  the UI if barcode exists in database on successful barcode scann.
                     double tq = obj.SelectSumOfInventory(itmName);
                      sp= obj.getLatestSP(noSpaceStr2,itmName);

                       stringBuffer= new StringBuffer();
                       stringBuffer2 = new StringBuffer();

                } catch (SQLException ex) {
                    Logger.getLogger(Sale.class.getName()).log(Level.SEVERE, null, ex);


          // Now adding the interface. 

       Toolkit.getDefaultToolkit().addAWTEventListener(barcodeListener, AWTEvent.KEY_EVENT_MASK);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.