Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-13-2007, 09:32 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
Problems with jButton ActionPerformed
I have created two buttons, previous and next this below is an event inside my button when jButton13 is clicked

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-13-2007, 09:54 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
So, what is your problem?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-13-2007, 11:03 PM
Member
 
Join Date: Jul 2007
Posts: 44
susan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-07-2007, 05:19 AM
Member
 
Join Date: Jul 2007
Posts: 40
cachi is on a distinguished road
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
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:
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Issue with Buttons and ActionPerformed Deathmonger Advanced Java 1 04-17-2008 09:47 AM
Help with actionPerformed Statements wco5002 New To Java 8 03-26-2008 05:02 AM
actionPerformed problem tomitzel New To Java 1 01-08-2008 07:10 PM
Need help with JButton event adlb1300 New To Java 2 11-19-2007 02:15 AM
Mouse over JButton sandor AWT / Swing 1 05-17-2007 10:15 PM


All times are GMT +3. The time now is 01:10 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org