0

I'm running some webcam captures in a thread like so:

class Capture implements Runnable { 
 @Override
 public void run() {
 while(true){
 //capture images
 //sleep 5 seconds
 }
}
//To actually start the capture
new Capture().run();

I'm doing this constantly, so I expect to still be able to perform UI functions like clicking on buttons while this is going on, but that's not the case. The x button on my JFrame is unresponsive, and same with other UI components.

Do I need to do something other than just using a separate thread? Doesn't seem to be working for me. Thanks

ΦXocę 웃 Пepeúpa ツ
48.4k17 gold badges76 silver badges102 bronze badges
asked Oct 16, 2016 at 12:50

2 Answers 2

2

You have just implemented Runnable. You haven't started a Thread to do the job. Try this:

new Thread(new Capture()).start();

Also consider Timer class for such job.

answered Oct 16, 2016 at 12:58

1 Comment

Yeah, that was it. Knew I was missing something simple; thanks for the quick reply.
1

This is happening because you are calling the run method but not starting the Thread when you do new Capture().run(); you are not even creating an instance of the Thread

Do I need to do something other than just using a separate thread?

yes, create and start the thread doing instead

new Thread(new Capture()).start();
answered Oct 16, 2016 at 12:51

1 Comment

new Capture().start(); this will result in compilation error as Capture does not extends Thread.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.