Results 1 to 4 of 4
  1. #1
    Bogdan is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default textField manipulation

    Having a number of different textFields with different variable names: "txtFieldA1"; "txtFieldA2"; "txtFieldA3" ... etc. , in which different values are stored so that they will be put into an array.

    is it possible make a for loop so that it the ide goes through all the textfields and assigns the values into the array by incrementing only the last character on the variable name string?

    here's what i'm thinking about:

    array[#] = Integer.parseInt(txtFieldA#.getText) //where '#' is the value I want to increment

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    No it's not possible in Java. Why not get rid of the variable names and place the "textfields" in an array to begin with? And what are text fields? Are they Swing JTextFields? AWT TextFields? SWT?

  3. #3
    Bogdan is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    NetBeans standard palette generated Javax.swing.JTextFields

    this part is in the GUI, so that the values from them are used in IFS for a fractal generator.

    basically, each function looks like [ F = x*a + y*b + c ] where a,b,c are values taken from the text fields

    I've got around 35 of these text fields and all have different names that differenciate by the last 2 characters : "txtInA0 / txtInB5 / etc".

    the program assigns the values in the text fields to a matrix.... I want to know if there is a way to manipulate the code so that it compares the variable name to a string in which I change the last two characted to what I need.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Bogdan View Post
    the program assigns the values in the text fields to a matrix.... I want to know if there is a way to manipulate the code so that it compares the variable name to a string in which I change the last two characted to what I need.
    That would be a bad design even if it were possible. To get a better design, you may want to show some code.

Similar Threads

  1. String Manipulation
    By tmotse in forum New To Java
    Replies: 1
    Last Post: 10-14-2010, 01:25 PM
  2. Image Manipulation
    By sh100 in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:18 AM
  3. Image manipulation
    By spike72 in forum Java 2D
    Replies: 1
    Last Post: 08-28-2009, 08:45 PM
  4. Image manipulation.
    By ambikark in forum Advanced Java
    Replies: 0
    Last Post: 10-15-2008, 01:37 PM
  5. Array manipulation
    By Ms.Ranjan in forum New To Java
    Replies: 9
    Last Post: 07-18-2008, 09:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •