I am newer to java and working with JFrame for the first time. This is what I have wrote so far.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class contact extends JFrame implements ActionListener
{
public contact()
{
ImageIcon usIcon = new ImageIcon("image/usIcon.gif");
JTextField First = new JTextField(10);
JTextField Middle = new JTextField(10);
JTextField Last = new JTextField(10);
JTextField Address = new JTextField(15);
JTextField City = new JTextField(15);
JTextField State = new JTextField(2);
JTextField Zip = new JTextField(5);
JTextField hPhone = new JTextField(10);
JTextField wPhone = new JTextField(10);
JTextField email = new JTextField(15);
JTextField gender = new JTextField(1);
JLabel firstLabel = new JLabel("First Name:");
JLabel middLabel = new JLabel("Middle Name:");
JLabel lastLabel = new JLabel("Last Name:");
JLabel addressLabel = new JLabel("Address:");
JLabel cityLabel = new JLabel("City:");
JLabel stateLabel = new JLabel("State:");
JLabel zipLabel = new JLabel("Zip:");
JLabel homeLabel = new JLabel("Home Phone:");
JLabel workLabel = new JLabel("Work Phone:");
JLabel emailLabel = new JLabel("Email:");
JLabel genderLabel = new JLabel("Gender:");
JButton forward = new JButton("Back");
JButton back = new JButton("Forward");
JPanel pFirst = new JPanel();
pFirst.setLayout(new GridLayout(2, 1));
pFirst.add(firstLabel);
pFirst.add(First);
JPanel pMiddle = new JPanel();
pMiddle.setLayout(new GridLayout(2, 1));
pMiddle.add(middLabel);
pMiddle.add(Middle);
JPanel pLast = new JPanel();
pLast.setLayout(new GridLayout(2, 1));
pLast.add(lastLabel);
pLast.add(Last);
JPanel pAdd = new JPanel();
pAdd.setLayout(new GridLayout(2, 1));
pAdd.add(addressLabel);
pAdd.add(Address);
JPanel pCity = new JPanel();
pCity.setLayout(new GridLayout(2, 1));
pCity.add(cityLabel);
pCity.add(City);
JPanel pState = new JPanel();
pState.setLayout(new GridLayout(2, 1));
pState.add(stateLabel);
pState.add(State);
JPanel pZip = new JPanel();
pZip.setLayout(new GridLayout(2, 1));
pZip.add(zipLabel);
pZip.add(Zip);
JPanel pHPhone = new JPanel();
pHPhone.setLayout(new GridLayout(2, 1));
pHPhone.add(homeLabel);
pHPhone.add(hPhone);
JPanel pWPhone = new JPanel();
pWPhone.setLayout(new GridLayout(2, 1));
pWPhone.add(workLabel);
pWPhone.add(wPhone);
JPanel pEmail = new JPanel();
pEmail.setLayout(new GridLayout(2, 1));
pEmail.add(emailLabel);
pEmail.add(email);
JPanel pGender = new JPanel();
pGender.setLayout(new GridLayout(2, 1));
pGender.add(genderLabel);
pGender.add(gender);
JPanel pForward = new JPanel();
pForward.add(forward);
JPanel pBack = new JPanel();
pBack.add(back);
back.addActionListener(this);
JPanel pName = new JPanel();
pName.add(pFirst);
pName.add(pMiddle);
pName.add(pLast);
JPanel pRes = new JPanel();
pRes.add(pAdd);
pRes.add(pCity);
pRes.add(pState);
pRes.add(pZip);
pRes.add(pHPhone);
pRes.add(pWPhone);
pRes.add(pEmail);
JPanel pButtons = new JPanel();
pButtons.add(pBack);
pButtons.add(pForward);
add(pName, "North");
add(pRes, "Center");
add(pButtons, "South");
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().equals("Back"))
{
String fullString = "Geroge";
First.setText(fullString);
}
}
public static void main(String[] args)
{
// Create a frame and set its properties
JFrame frame = new contact();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
What I want to do is display the information into the text field for the first name when a button is pushed. I am just using the back button as an example. If you could help I would appreciate it. Thank you.