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,gb c);
gbc.gridx = 0;
gbc.gridy++;
publisher = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("PUBLISHER"),publis her,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"),categor y,gbc);
gbc.gridx = 0;
gbc.gridy++;
book_number = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("NUMBER"),book_numb er,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);
}
}
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
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,gb
gbc.gridx = 0;
gbc.gridy++;
publisher = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("PUBLISHER"),publis
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"),categor
gbc.gridx = 0;
gbc.gridy++;
book_number = new JTextField(20),gbc);
gbc.gridx = 1;
tPanel.add(new JLabel("NUMBER"),book_numb
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ta :-)