Hi Java Experts,
I'm trying to take an existing application and add some custom labels
to the program variables. Specifically, I want to change every scalar
variable to an array type such that I can store the value of the
variable at index 0 of the array and store some label at index 1 of
the array. Rather than manually change every variable one line at a
time, can anyone suggest a more efficient way of doing this?
Thanks,
Shirley
Roedy Green - 14 Nov 2007 03:46 GMT
On Tue, 13 Nov 2007 19:39:43 -0800, Shirley Cohen
<shirley.cohen@gmail.com> wrote, quoted or indirectly quoted someone
who said :
>I'm trying to take an existing application and add some custom labels
>to the program variables. Specifically, I want to change every scalar
>variable to an array type such that I can store the value of the
>variable at index 0 of the array and store some label at index 1 of
>the array. Rather than manually change every variable one line at a
>time, can anyone suggest a more efficient way of doing this?
Do a global change "JLabel " to "JLabel[] " deciding as you go which
ones to change. Then the IDE compile/syntax check will point out the
places where you have to add a subscript or loop/subscript

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Stefan Ram - 14 Nov 2007 04:38 GMT
>I'm trying to take an existing application and add some custom
>labels to the program variables. Specifically, I want to change
[quoted text clipped - 3 lines]
>every variable one line at a time, can anyone suggest a more
>efficient way of doing this?
This makes no sense, because in Java, according to the JLS3,
the components of an array also are called »variables«. So, if
every variable should become an array this would apply to
array components, too. But array components can not be arrays.
(And even, if you would make them into reference variable
referencing arrays, this would become and endless process.)
Also, in the JLS3, there are no terms »program variable« or
»scalar variable«, so it is not easy to guess what these terms
should refer to.
So, if you are in a hurry, and have no time to learn Java
yourself, the most efficient way, would be to do something you
are good in and then take the money earned with this to hire a
developer. Then, tell him what you actually want to achieve
(not /how/ you think it might be done in Java).
Manish Pandit - 14 Nov 2007 04:46 GMT
> Hi Java Experts,
>
[quoted text clipped - 8 lines]
>
> Shirley
The better/more elegant approach would be to encapsulate the label and
the value in an object, with an API like get/setLabel() and get/
setValue(). Replace the variables (where you need labels) with
instances of this object and use the setters/getters.
-cheers,
Manish
Martin Gregorie - 14 Nov 2007 12:59 GMT
> Hi Java Experts,
>
[quoted text clipped - 4 lines]
> the array. Rather than manually change every variable one line at a
> time, can anyone suggest a more efficient way of doing this?
I agree with Roedy's replacement edit. Of course, to do that you need to
use an editor capable of handling regular expressions (vi, microemacs or
emacs would all do, or [in extremis] write a program in perl, awk or
even Java).
However, you'd get better advice if you tell us why you need to do this
and what you hope to achieve by doing it rather than simply saying how
one possible solution might work.
I agree with another Manish: declaring a class rather than using an
array would probably be a much better solution. For starters it gets
round the obvious problem that a simple array won't hold an int as [0]
and a string label as [1].

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Martin Gregorie - 14 Nov 2007 14:01 GMT
> I agree with another Manish:
Ulp. Mistyped that. Apologies.

Signature
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |