I am working on a project and I needed to read barcode from camera. I am able to capture images and decode them but only problem remaining is that I need the 'capture and decode' process to work until user stops it. So for what I could achieve is this
btnCapture = new JButton("Capture");
btnCapture.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// camera is already initialized and ready to use
// take image from webcam
image = webcam.getImage();
// convert the image to show it on a label
lblNewLabel.setIcon((imageCont.convertToImageIcon(image,lblNewLabel)));
}
});
btnCapture.setBounds(508, 151, 89, 23);
add(btnCapture);
this process is working fine but I need it to work not once but continuously when the user press btnCapture for that I tried this
while(true)
{
// camera is already initialized and ready to use
// take image from webcam
image = webcam.getImage();
// convert the image to show it on a label
lblNewLabel.setIcon((imageCont.convertToImageIcon(image,lblNewLabel)));
}
When I tried this this freezes the UI. please help me with this I researched about it and got the idea of making a thread but I could not make it.
doInBackground
method. This will run this code in a background thread, and will prevent it from freezing the Swing event thread.For more on this, please read Lesson: Concurrency in Swing.