Results 1 to 4 of 4
  1. #1
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default Problems with jButton ActionPerformed

    I have created two buttons, previous and next this below is an event inside my button when jButton13 is clicked

    Java Code:
    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
    
    // searchResults();
    
    // System.out.println(name1);
    
    
    //displayClientData();
    
    //creating variable that will get colom values
    String initials;
    String nameDisp;
    String surname;
    String email;
    String company;
    String telephone;
    String fax;
    String physical_add;
    String street_name;
    String surburb;
    String city;
    String code;
    String postal_add;
    String post_str;
    String post_surb;
    String post_city;
    String post_code;
    String position;
    
    int client_id;
    
    name1=jTextField45.getText();
    
    if(this.jTextField45.getText() != "")
    {
    
    jTextField45.setText(""); //Clear the textField after submiting.
    
    //System.out.println(name1);
    //jTextField46.setEditable(false);
    //email1 = jTextField47.getText();
    //position1 =jTextField49.getText();
    
    
    String sql2 = "SELECT t1.client_id,t1.company_id,t1.initials,t1.name,t1.surname,t1.email,t1.position,t2.company_id,t2.comp any_name,t2.phone,t2.fax,t2.physical_add," +
    " t2.street_name,t2.surburb,t2.code,t2.city,t2.postal_add,t2.post_str,t2.post_surb,post_city,postal_co de " +
    "FROM client AS t1, company AS t2 where t1.company_id = t2.company_id AND t1.name LIKE '"+name1+"' ";
    
    
    try
    {
    this.resultSet = this.connection.executeQuery(sql2);
    
    while(this.resultSet.next())
    {
    //get the values from the database coloms values assing them to the String variable
    
    //jTextField45.setText(" ");
    client_id = this.resultSet.getInt("client_id");
    jButton15.setEnabled(true);
    //jButton14.setEnabled()
    //System.out.println(client_id);
    
    
    initials = this.resultSet.getString("initials");
    nameDisp = this.resultSet.getString("name");
    surname = this.resultSet.getString("surname");
    email = this.resultSet.getString("email");
    position= this.resultSet.getString("position");
    company = this.resultSet.getString("company_name");
    telephone = this.resultSet.getString("phone");
    fax = this.resultSet.getString("fax");
    physical_add = this.resultSet.getString("physical_add");
    street_name = this.resultSet.getString("street_name");
    surburb = this.resultSet.getString("surburb");
    code = this.resultSet.getString("code");
    city = this.resultSet.getString("city");
    postal_add = this.resultSet.getString("postal_add");
    post_str = this.resultSet.getString("post_str");
    post_surb = this.resultSet.getString("post_surb");
    post_city = this.resultSet.getString("post_city");
    post_code = this.resultSet.getString("postal_code");
    
    
    //displaying the results on the textField
    jTextField27.setText(initials);
    jTextField28.setText(nameDisp);
    jTextField29.setText(surname);
    jTextField33.setText(email);
    jTextField31.setText(company);
    jTextField32.setText(telephone);
    jTextField34.setText(fax);
    jTextField35.setText(physical_add);
    jTextField36.setText(street_name);
    jTextField37.setText(surburb);
    jTextField38.setText(city);
    jTextField39.setText(code);
    jTextField40.setText(postal_add);
    jTextField41.setText(post_str);
    jTextField42.setText(post_surb);
    jTextField43.setText(post_city);
    jTextField44.setText(post_code);
    jTextField11.setText(position);
    //System.out.println(nameDisp);
    
    
    }
    
    }
    
    catch( SQLException e )
    {
    e.printStackTrace( System.err );
    //this.connection.close();
    }
    
    
    } //End of IF statement for name search value
    
    //surname1=jTextField46.getSet(" ");
    
    if (this.jTextField46.getText() != "")
    {
    surname1=jTextField46.getText();
    
    
    System.out.println(surname1);
    
    String sql2 = "SELECT t1.client_id,t1.company_id,t1.initials,t1.name,t1.surname,t1.email,t1.position,t2.company_id,t2.comp any_name,t2.phone,t2.fax,t2.physical_add," +
    " t2.street_name,t2.surburb,t2.code,t2.city,t2.postal_add,t2.post_str,t2.post_surb,post_city,postal_co de " +
    "FROM client AS t1, company AS t2 where t1.company_id = t2.company_id AND t1.surname LIKE '"+surname1+"' ";
    
    try
    {
    this.resultSet = this.connection.executeQuery(sql2);
    
    while(this.resultSet.next())
    {
    //get the values from the database coloms values assing them to the String variable
    
    
    client_id = this.resultSet.getInt("client_id");
    
    //System.out.println(client_id);
    
    
    initials = this.resultSet.getString("initials");
    nameDisp = this.resultSet.getString("name");
    surname = this.resultSet.getString("surname");
    email = this.resultSet.getString("email");
    position= this.resultSet.getString("position");
    company = this.resultSet.getString("company_name");
    telephone = this.resultSet.getString("phone");
    fax = this.resultSet.getString("fax");
    physical_add = this.resultSet.getString("physical_add");
    street_name = this.resultSet.getString("street_name");
    surburb = this.resultSet.getString("surburb");
    code = this.resultSet.getString("code");
    city = this.resultSet.getString("city");
    postal_add = this.resultSet.getString("postal_add");
    post_str = this.resultSet.getString("post_str");
    post_surb = this.resultSet.getString("post_surb");
    post_city = this.resultSet.getString("post_city");
    post_code = this.resultSet.getString("postal_code");
    
    
    //displaying the results on the textField
    jTextField27.setText(initials);
    jTextField28.setText(nameDisp);
    jTextField29.setText(surname);
    jTextField33.setText(email);
    jTextField31.setText(company);
    jTextField32.setText(telephone);
    jTextField34.setText(fax);
    jTextField35.setText(physical_add);
    jTextField36.setText(street_name);
    jTextField37.setText(surburb);
    jTextField38.setText(city);
    jTextField39.setText(code);
    jTextField40.setText(postal_add);
    jTextField41.setText(post_str);
    jTextField42.setText(post_surb);
    jTextField43.setText(post_city);
    jTextField44.setText(post_code);
    jTextField11.setText(position);
    //System.out.println(nameDisp);
    
    }
    
    } //end of try
    
    
    catch( SQLException e )
    {
    e.printStackTrace( System.err );
    //this.connection.close();
    }
    }
    
    
    } //end of method

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    So, what is your problem? :)

  3. #3
    susan is offline Member
    Join Date
    Jul 2007
    Posts
    44
    Rep Power
    0

    Default

    Sorry....
    Could someone please help me with a java form,i a form where you search the database then it displays the results on the text fields, i have a next button and previous button.
    The problem i am faced with is that i can not make my form to go to the next record when you click the next button or the previous button.

    Can someone with a bit more knowledge in java give me a clue what to do for i have never done something like this before.

    Thanks.

  4. #4
    cachi is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    It is your if statements checking if a list is "".

    In Java a String is treated as an object. Since it is not a primitive type (like an int, float, double, char), you cannot do boolean comparisons such as == != >, etc.

    Instead you have to use something in the String class called equals or equalsIgnoreCase.

    Both these method take in a string as a parameter and return true if that String is the same as the string it is being called upon. For example
    Java Code:
    String test = "test"
    
    if(test == "test")
      System.out.println("TEST WORKED");
    The above code may work once, maybe a couple times. However most likely it wont. It wont print anything. Why? Because since Strings are treated as Objects, they are used just like Objects. That is they are referenced. When you do an == you are checking if the first String test is the same reference as the String "test". NOT if they are the same String.

    The correct way:
    Java Code:
    if(test.equals("test"))
      System.out.println("String comparison worked!");
    Will return true every time and print every time.

    Sorry if this seems spaced out. I am working off of a full night of no sleep after programming in Lisp.
    Greetings.

Similar Threads

  1. Issue with Buttons and ActionPerformed
    By Deathmonger in forum Advanced Java
    Replies: 1
    Last Post: 04-17-2008, 08:47 AM
  2. Help with actionPerformed Statements
    By wco5002 in forum New To Java
    Replies: 8
    Last Post: 03-26-2008, 04:02 AM
  3. actionPerformed problem
    By tomitzel in forum New To Java
    Replies: 1
    Last Post: 01-08-2008, 06:10 PM
  4. Need help with JButton event
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-19-2007, 01:15 AM
  5. Mouse over JButton
    By sandor in forum AWT / Swing
    Replies: 1
    Last Post: 05-17-2007, 09:15 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
  •