User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2007
Posts: 3
Reputation: #1Basser is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
#1Basser #1Basser is offline Offline
Newbie Poster

Help Displaying information in Text fields

  #1  
Nov 7th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 19
Solved Threads: 200
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Displaying information in Text fields

  #2  
Nov 8th, 2007
you'll need to add a ButtonListener (or was that KeyListener...) to change for button presses.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 5:06 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC