variable names and JTextField

i need to give a variable name to each of my JTextField and then add it to the panel how do i do about this without errors this is my code...please write comments right next to the code where it should be added

import java.awt.*;
import javax.swing.*;
public class Administration
{
            
      
      JTextField tittle, author, publisher, year, isbn, category, book_number, unit_price;
      JButton search, update, clear, add;
      JPanel Panel, tPanel;
      JPanel AdminPanel;
      Container c = getContentPane();

public Administration()
{
      makeGUI();
}


//CREATE THE USER INTERFACE
void makeGUI()
{
    c.setLayout(new BorderLayout());
      AdminPanel = new JPanel(new BorderLayout());

tPanel = new JPanel(new GridBagLayout());
tPanel.setBackground(Color.magenta);

GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;



title = new JTextField(20),gbc);
gbc.gridx = 1;
gbc.gridy = 0;
tPanel.add(new JLabel("TITLE"),title,gbc);
gbc.gridx = 0;
gbc.gridy++;
author = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("AUTHOR"),author,gbc);
gbc.gridx = 0;
gbc.gridy++;
publisher = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("PUBLISHER"),publisher,gbc);
gbc.gridx = 0;
gbc.gridy++;
year = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("YEAR"),year,gbc);
gbc.gridx = 0;
gbc.gridy++;
isbn = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("ISBN"),isbn,gbc);
gbc.gridx = 0;
gbc.gridy++;
category = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("CATEGORY"),category,gbc);
gbc.gridx = 0;
gbc.gridy++;
book_number = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("NUMBER"),book_number,gbc);
gbc.gridx = 0;
gbc.gridy++;
unit_price = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("UNIT PRICE"),unit_price,gbc);
gbc.gridx = 0;
gbc.gridy++;

AdminPanel.add(tPanel, BorderLayout.NORTH)

c.setVisible(true);
      }
}
LVL 1
lucinda77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

esorfCommented:
I think the pattern you're looking for is:

            author = new JTextField(20); // Create author text field
            gbc.gridx = 0;  // Set X to the field column
            gbc.gridy++;  // Move down a row
            tPanel.add(author, gbc);  // Add it to the panel
            gbc.gridx = 1;  // Move over to the label column
            tPanel.add(new JLabel("AUTHOR"), gbc);  // Add the label

There should be a block like this for each text field, replacing the field member variable and label appropriately.

Cheers,

- Frank
0
DrWarezzCommented:
..to assign text from a variable to a JTextField, use this:

JTextField jtf = new JTextField();
pane.add( jtf);
// ...
String text = "something...";
jtf.setText( text );

gL,
[r.D]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrWarezzCommented:
ta :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.