Results 1 to 3 of 3
  1. #1
    kbgriggs is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Next and Previous Buttons

    Help.....I am new to java and trying to add first, next, previous and last buttons to my gui. I have all my code working but whenever I try and I have tried a lot of things, everything gets screwed up. Here is a section of my code:

    Java Code:
                public void actionPerformed(ActionEvent e)
                {
    
                      //add button functions
    
                      if (e.getActionCommand() == "First") // First is the caption (label) on my button. If the button I click is First, the following statements will execute.
                      {
    
                            prodnameField.setText(software[0].getprodname()); // get the name of the first person in my array and display it in the name text box.
    
                            itemnumField.setText(String.valueOf(software[0].getitemnum())); // get the age of the first person in my array and display it in the age text box.
    
                            prodpriceField.setText(String.valueOf(software[0].getprodprice())); // get the weight of the first person in my array and display it in the weight text box.
    
    
    
                      } // end if
    
                           if (e.getActionCommand() == "Next") // First is the caption (label) on my button. If the button I click is First, the following statements will execute.
                      {
    
                            prodnameField.setText(software[1].getprodname()); // get the name of the first person in my array and display it in the name text box.
    
                            itemnumField.setText(String.valueOf(software[2].getitemnum())); // get the age of the first person in my array and display it in the age text box.
    
                            prodpriceField.setText(String.valueOf(software[2].getprodprice())); // get the weight of the first person in my array and display it in the weight text box.
    
    
    
                      } // end if
    
    
    
    
    
                      if (e.getActionCommand() == "Last") // Last is the caption (label) on my button. If the button I click is labeled Last, the following statements will execute.
    
                            prodnameField.setText(software[4].getprodname()); // get the name of the last person in my array and display it in the name text box.
    
                      itemnumField.setText(String.valueOf(software[4].getitemnum())); // get the age of the last person in my array and display it in the age text box.
    
                      prodpriceField.setText(String.valueOf(software[4].getprodprice())); // get the weight of the last person in my array and display it in the weight text box.
    
                } // end if

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    i think you missing {} for "Last" button

    and you just hard code "Next" to get xxx[2], not really do "Next"

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Added to mtyoungs suggestion

    one more thing I want to tell here.


    always use equals() method instead of "==" and always trim the string before comparing.
    Ramya:cool:

Similar Threads

  1. Java next and previous button
    By florentp in forum New To Java
    Replies: 0
    Last Post: 03-18-2009, 06:10 AM
  2. add previous jar library to new one
    By Farzaneh in forum Eclipse
    Replies: 1
    Last Post: 08-23-2008, 03:31 PM
  3. help..on Next n Previous Button
    By norazanita in forum New To Java
    Replies: 0
    Last Post: 06-12-2008, 06:58 AM
  4. Next and Previous Buttons
    By JavaNewb in forum New To Java
    Replies: 1
    Last Post: 05-09-2008, 02:23 AM
  5. Using previous with CardLayout
    By uncopywritable in forum New To Java
    Replies: 2
    Last Post: 08-05-2007, 10:43 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
  •