•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,233 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,778 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 749 | Replies: 1
![]() |
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Populating Multiple Text Fields Based On A Dynamic Drop-Down List Selection (PHP)
- text fields (Site Layout and Usability)
- Reading and Displaying a comma delimited text file to a table. (ASP)
- Resizing text fields (JavaScript / DHTML / AJAX)
- Form Fields (JavaScript / DHTML / AJAX)
Other Threads in the Java Forum
- Previous Thread: Need Help with JFrame
- Next Thread: What in the world is the problem?



Linear Mode