Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

control of jtextfields  RSS feed

 
peter m hayward
Ranch Hand
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in the current project, I have a number of JTextfields that are used to input data about a given book.
the problem that i am having is that this data is then used to update a mysql database, so i need a method to prevent the update occurring if any of these textfields are empty
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When is the update triggered? Does the user enter the data and then clicks some button perhaps?
 
peter m hayward
Ranch Hand
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi the problem is gathering all the data to pass to the insert query to give an example if i scan the isbn and it not in the database then i need to update the database by typing the author title publisher etc in separate jtextfields and hope fully pass this to the mysql query thus updating.

i tried having the button disable/ invisible until all jtextfields had been filled but could not find a method to do this as the event fired by one jtextfield would not be able to see the contents of the other jtextfields

so to be clear i think what i need to do is have a button that is disable until all the correct data as been entered in all jtextfields

 
Tony Docherty
Bartender
Posts: 3264
81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would help to see some of your code so we can see how you have structured it. For example do you add anonymous inner class listeners to each of the JTextFields?
 
peter m hayward
Ranch Hand
Posts: 78
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony
below is the code for the retrieval of the data from mysql it gets here from a mylistener which is a document listener it arrives with the isbn thus is able to determine if the book is in the database, now the problem prevails when its not the textfields need to be all filled before i attempt to update mysql otherwise say for arguments sake i missed out the title and mysql has a non blank set on the author table then nothing will happen and i will not be achieving my objective of adding a new book to the database
one thought i had over night all these textfiels are on a jpanel so could i some how scan the panel object and check their contents thus using the parent relationship of the textfields to the panel


 
david foley
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use try catch exceptions

If the text fields are null give error else run
Run Update SQL
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!