Jdbc


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Jdbc

  1. #1
    Join Date
    Oct 2004
    Posts
    4

    Jdbc

    I' ve create a list for storing ResultSet results and navigate through records, using buttons (first, last, previous and next).
    I can access its first and last elements.
    However, when clicking next or previous buttons, the list moves only once, to next or previous items.
    How can I move it, forward or backward, every time I click the button ?
    Thanks.

    That's my code (for next button)

    class Listener implements ActionListener {
    public void actionPerformed(ActionEvent e) {

    int x = list1.getItemCount()-1;
    int i = 0;
    if(x > i){
    x--;
    String str = list1.getItem(x);
    t1.setText(str);
    }
    }
    }

  2. #2
    Join Date
    Oct 2004
    Location
    UK
    Posts
    12

    Re: Jdbc

    If I understand you correctly you will need a variable with scope outside of your function (e.g. in the Listener class, or the enclosing class) to store the current list position, which you then increment or decrement when moving forwards or backwards respectively.

  3. #3
    Join Date
    Oct 2004
    Posts
    4
    And how to change my code in order to do it ?

  4. #4
    Join Date
    Oct 2004
    Location
    UK
    Posts
    12
    Something like this, but of course with range checking added:
    Code:
    class Listener implements ActionListener
    {
        /*
            Assuming you're using the same instance of
            Listener for each control, otherwise this
            variable will need to be static
        */
    
        private int position = 0;
        
        public void actionPerformed(ActionEvent e)
        {
            if (e.getActionCommand().equals("forward"))
            {
                position++;
            }
            else if (e.getActionCommand().equals("back"))
            {
                position--;
            }
            else
            {
                // whatever other commands you need
            }
            
            String str = list1.getItem(x);
            t1.setText(str);
        }
    }

  5. #5
    Join Date
    Oct 2004
    Posts
    4
    Thank you, it works !
    But, how to synchronize the next and previous buttons, providing each one "knows" the item position ?

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