textField With array Question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: textField With array Question

Threaded View

  1. #1
    Join Date
    Apr 2006
    Posts
    8

    textField With array Question

    Hi I have the following code:

    textString = textField.getText();
    num = Integer.parseInt(textString);



    if ( num >= name.length-name.length && num <= name.length-1) {

    if ( e.getSource() == first ) {
    currentEntry = name.length - name.length;
    textField.setText(textString = Integer.toString(currentEntry));
    }


    if ( e.getSource() == previous && currentEntry > name.length - name.length ) {
    currentEntry--;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == next && currentEntry < name.length-1){
    currentEntry++;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == last ) {
    currentEntry = name.length-1;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == goTo ) {
    currentEntry = num;
    textField.setText(textString = Integer.toString(currentEntry));
    }
    }

    else {
    if ( e.getSource() == first ) {
    currentEntry = name.length - name.length;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == previous && currentEntry > name.length - name.length ) {
    currentEntry--;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == next && currentEntry < name.length-1 ) {
    currentEntry++;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == last ) {
    currentEntry = name.length-1;
    textField.setText(textString = Integer.toString(currentEntry));
    }

    if ( e.getSource() == goTo ) {
    num = currentEntry;
    textField.setText(textString = Integer.toString(currentEntry));
    }
    }

    Basically as you can see there are 5 buttons and a textField. The code given here does work, it starts off with a zero in the text field which is the number of the first index in the array name[], each index in the array stores some personal details which is shown on screen. So when the 'last' button is pressed the number in the textfield should now contain the last index number in the array, here for example this would be 4, and the information of that index is displayed on screen. The 'first', 'next' and 'previous' buttons are pretty self explanatory in what they do. Also the 'goTo' button when pressed displays the information of that particular index number that has been entered into the textField.

    Also when the 'previous' button is pressed and the information deisplayed is of the first index nothing happens, and similarly with the 'next' button and the last index. Also if the number entered into the textField is not an index number, either too high, or too low (giving a negitive number), nothing happens and the current information is still displayed with the correct number in the textField displayed appropriatley.

    All I am wondering is, is there a way to achieve all of this, but with a smaller amount of code, i.e without so many if statements?

    Thanks
    Last edited by donce; 04-15-2006 at 08:05 AM.

Similar Threads

  1. array of arrays question
    By jim in forum Java
    Replies: 3
    Last Post: 10-19-2001, 09:24 AM
  2. accessing textfield elements in a array
    By dominic in forum Java
    Replies: 2
    Last Post: 04-30-2001, 03:27 AM
  3. casting array of array question???
    By Xasting in forum Java
    Replies: 1
    Last Post: 03-16-2001, 10:38 PM
  4. casting array of array question???
    By Xasting in forum Java
    Replies: 0
    Last Post: 03-15-2001, 05:08 PM
  5. Replies: 1
    Last Post: 08-18-2000, 12:29 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center