Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Seeing textfields

Posted on 2013-11-20
10
172 Views
Last Modified: 2013-12-02
following is my code to populate some textfields.  The textfields are defined in the main program so I get errors saying can't find the textfields.  How do I let this class know about the textfields.  Thanks

public class populateInvName {
    ConnectDatabase connectDatabase = new ConnectDatabase();    
    public Connection con;
       
       
    public void populateInvName() {

         try {

            con = connectDatabase.getConnection();
            Statement st = (Statement) con.createStatement();
            String command = "SELECT * FROM seller WHERE name = " + "'" + entry +"'";
                 ResultSet rec = st.executeQuery ( command );
                 
            rec.next();            
           
            jTextField_dailySellerNumber.setText(rec.getString("number"));
            jTextField_dailySellerName.setText(rec.getString("name"));
            jTextField_dailySellerAddress1.setText(rec.getString("address1"));
            jTextField_dailySellerAddress2.setText(rec.getString("address2"));
            jTextField_dailySellerCity.setText(rec.getString("city"));
            jTextField_dailySellerState.setText(rec.getString("state"));
            jTextField_dailySellerZip.setText(rec.getString("zip"));
            jTextField_dailySellerMortgage.setText(rec.getString("mortgage"));
            jTextField_dailySellerComment.setText(rec.getString("comment"));
            jTextField_dailySellerHeadIn.setText(rec.getString("head"));
           
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,
                "SQLException Reading Daily Seller: " + ex.getMessage());
        }
    }      
   
}
0
Comment
Question by:sargent240
  • 5
  • 4
10 Comments
 
LVL 11

Expert Comment

by:Manish
ID: 39665047
First set the value in some object like Person.
put it in list.

Call this class from main class and get the list.
Iterate that list in main class and set it in jTextField.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39665639
You could pass a Map to that method
    public void populateInvName(Map<String, JTextComponent> fieldsMap) {
        final String[] FIELD_NAMES = {
                "number", "name", "address1", "address2", "city", "state", "zip",
                "mortgage", "comment", "head"
            };
...
        if (rs.next()) {
            for (int i = 0; i < FIELD_NAMES.length; i++) {
                fieldsMap.get(FIELD_NAMES[i])
                         .setText(rs.getString(FIELD_NAMES[i]));
            }
        }

Open in new window

0
 

Author Comment

by:sargent240
ID: 39670892
Thanks CEHJ! One question, What do I send to the method when I call it for Map<String and JTextComponent>fieldsMap.

Thanks, Cheers.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 86

Expert Comment

by:CEHJ
ID: 39671338
Well you need to create a Map of course with all your fields keyed by column name
0
 

Author Comment

by:sargent240
ID: 39672796
I have been looking around at how to set up the map and am not grasping what I need to do.  Could you show me what the code should be as you did above?  THANKS!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39672824
fieldsMap = new HashMap<String, JTextComponent>();
fieldsMap.put("number", tfNumber);
fieldsMap.put("name", tfName);
...

Open in new window

0
 

Author Comment

by:sargent240
ID: 39673622
I used the code from your last post and got a:

cannot find symbol var variable

on fieldsMap, tfNumber, and tfName.

I am struggling with the syntax, continuing to search through info on the web without much success.  Besides the code I could use a little elementary discussion as to the parts involved.  That would help a lot as to future use of the idea.  Again Thank you very much.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39673898
I used the code from your last post and got a:

cannot find symbol var variable
Please post, verbatim, the error you got. Of course, you would have to define your Map variable as an instance variable
0
 

Author Closing Comment

by:sargent240
ID: 39689086
I got it figured out.  Thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39689546
:)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question