Stepper Example

Supporting Java SE version 7 and up

Stepper Example

Postby charleshuff1953 » Thu Apr 14, 2011 2:10 am

I would like to move the stepper motor until input 1 is triggered. I am using the full example. my code looks like...
This works but does not seem correct... Over long distances the screen and java app becomes unresponsive until the while is satisfied. How would I move the stepper until the input 1 is triggered using events? an example would be great but if not general advice would be welcome.


Posts: 90
Joined: Sun Nov 15, 2009 2:16 pm
Location: Lower Bavaria (Germany)

Re: Stepper Example

Postby RBBT » Thu Apr 14, 2011 3:13 am

if in1Chk is an instance of JCheckBox then you have to use the
appropriate Listener (ActionListener).

Don't poll on the eventdispatch thread! this makes your GUI unresponsive!
Best Regards from Lower Bavaria

User avatar
Lead Developer
Posts: 3166
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada

Re: Stepper Example

Postby Patrick » Fri Apr 15, 2011 9:17 am

You want to listen to the input change event and then stop the stepper from that listener - this way your GUI won't lock up. Have a look and the Java examples - both the full and simple, they both implement the input change event.



Re: Stepper Example

Postby charleshuff1953 » Fri Apr 15, 2011 2:06 pm

Thanks Robert and RBBT, you are both correct. I was looking for a Netbeans specific answer. I finally realized that I could add an event listener that was not action performed (but rather a state change event) and then I was able to create a button that set specific Jcheckbox vars that I could monitor in the input change event. After that I used one button to set sample temperature, humidity, time, and ambient temp all to null, select (and enable) the 'seeking' checkbox and send the stepper to a large positive step number. The input event listener then toggles 'seeking' to 'found' when the in1Chk status is true. The action event then can stop the motor and record all the above variables. I have it working now and I am very pleased. The answers are in the example files once you know where to look!

Have a great day....

Return to “Java”

Who is online

Users browsing this forum: No registered users and 3 guests