I need a way to take the output of a JSpinner with a custom value list - 00, 01, 02, etc, to 10 - and convert that to an ASCII decimal sequence. For example, "00" would like "48 48" and so on. I don't know how to do that conversion - a hint or a link would be helpful.
The second part of the problem comes when those new values have to be placed into the second and third slots of the example sequence below:
This looks like the means towards a goal. What is your goal?
Scott A Burch
Joined: Jan 04, 2011
The goal is to slide that array through a serial port via an outputstream to control an external device. My preliminary model works only when the array is "hard coded". I have to find a way for it to be more flexible so that a user can select a network of devices to control.
I am also missing why solving that problem reduces to the question you posted. If it were me I would just put a suitable list of objects into the spinner's model and just use data from those objects. Or something like that... I didn't read your requirement all that closely.
There are two smaller problems at hand here:
1) getting the JSpinner to show values from 00 to 10.
2) converting the current value to two digits.
For problem 1 you can use a SpinnerListModel if your inputs are limited in number. Otherwise, use a SpinnerNumberModel and a JSpinner.NumberEditor to display the value using two digits, then get the value back and use a NumberFormat to format it to two digits.
For problem 2 you can, with a two character String, simply get the two chars (charAt) and convert them to int to get the ASCII value - as long as the chars are digits of course.
My JSpinner actually works fine right now. I am using the ListModel and just populated the list with the items "01" "02" etc, up to "10". Thanks for the info on JSpinner NumberEditor; I was introduced to spinners on the fly for this project.
charAt should do the trick for decimal conversion.
I'll start a new thread for the next problem I have ... ha!