Link to home
Start Free TrialLog in
Avatar of lucinda77
lucinda77

asked on

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);
      }
}
SOLUTION
Avatar of esorf
esorf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DrWarezz
DrWarezz

ta :-)