Enter TextField info into TextBox

Dear experts,

I would like my program to when the user clicks on AddJob the information is deisplayed in a TextBox.

My code so far is:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JobApplication extends JFrame implements ActionListener
{
  //declaring the variables
  private JTextField Id;
  private  JTextField Customer;
  private  JTextField Paid;
  private  JTextField MaterialCost;
  private  JTextField NumberHourWorked;
  private  JTextField LabourCost;
  private  JTextField RatePerHour;
  private  JTextField TotalPayment;
  private static JobCollection collection = new JobCollection(100);

public JobApplication()
     {
   
              //panels
              JPanel p1 = new JPanel(false);
              JPanel p2 = new JPanel(false);
              p2.setLayout(new GridLayout(10,1));
             JPanel p3 = new JPanel(false);
             p3.setLayout(new GridLayout(10,1));//row/column
             JPanel p4 = new JPanel(false);

              //Place panels on frame
              getContentPane().add(p1, "South");
              getContentPane().add(p2, BorderLayout.CENTER);
              getContentPane().add(p3, BorderLayout.WEST);
              getContentPane().add(p4, "East");
     
     
               //panel P1 to hold the buttons
               JButton AddJob = new JButton("AddJob");
      AddJob.setForeground(Color.blue);
      AddJob.addActionListener(this);
                p1.add(AddJob);
           
                     
             //Panel2 to hold text
             //creating a ID Textfield
       
        Id = new JTextField(10);
        Id.setHorizontalAlignment(JTextField.RIGHT);
        Id.addActionListener(this);
        p2.add(Id);

       //creating a Customer Textfield
       Customer= new JTextField(10);
       Customer.setHorizontalAlignment(JTextField.RIGHT);
       Customer.addActionListener(this);
       p2.add(Customer);

      //creating a Paid Textfield
      Paid= new JTextField(10);
      Paid.addActionListener(this);
      Paid.setHorizontalAlignment(JTextField.RIGHT);
      p2.add(Paid);
         
     //creating a Material Cost Textfield
     MaterialCost= new JTextField(10);
     MaterialCost.setHorizontalAlignment(JTextField.RIGHT);
     MaterialCost.addActionListener(this);
     p2.add(MaterialCost);

     //creating a LabourCost Textfield
     LabourCost= new JTextField(10);
     LabourCost.setHorizontalAlignment(JTextField.RIGHT);
     LabourCost.addActionListener(this);
     p2.add(LabourCost);

     TotalPayment= new JTextField(10);
     TotalPayment.setHorizontalAlignment(JTextField.RIGHT);
     TotalPayment.addActionListener(this);
     p2.add(TotalPayment);

            //Panel p3 to hold labels
           //creating the ID label
           JLabel myLabel;
           myLabel =new JLabel("Input ID", SwingConstants.RIGHT);
           p3.add(myLabel);

          //creating a Customer label
          JLabel myLabel1;
          myLabel1 = new JLabel("Input Customer",SwingConstants.RIGHT);
          p3.add(myLabel1);

         //creating a Paid label
         JLabel myLabel2;
         myLabel2 = new JLabel("Input Paid",SwingConstants.RIGHT);
         p3.add(myLabel2);

         //creating a Material Cost label
         JLabel myLabel3;
         myLabel3 = new JLabel("Input Material Cost",SwingConstants.RIGHT);
         p3.add(myLabel3);
         
          //creating a LabourCost label
         JLabel myLabel6;
         myLabel6 = new JLabel("Input LabourCost",SwingConstants.RIGHT);
          p3.add(myLabel6);

         JLabel myLabel7;
         myLabel7 = new JLabel("Total Payment",SwingConstants.RIGHT);
          p3.add(myLabel7);

               //TextArea created
      JTextArea displayArea;
      displayArea = new JTextArea(15, 11);
      p4.add(displayArea);

              //making the frame
               setTitle("Job Application");
               setBounds(0,0,700,500);
               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               setVisible(true);

public void actionPerformed(ActionEvent e)
{
      String text1 = Id.getText();
     String text2 = Customer.getText();
      String text = Paid.getText();
 
            
                  try
                  {
                    Double.parseDouble(MaterialCost.getText());
                  }
                       catch (NumberFormatException nfe)
                       {
                                 if(MaterialCost.getText().equals(""))
            {
                 System.out.println("ERROR: Please enter an Material Cost ");
            }
                      else
                      {
                             System.out.println("ERROR: Material cost is not an integer");
                      }
                        }


                try
                {
                               Double.parseDouble(LabourCost.getText());
                 }
            catch (NumberFormatException nfe)
            {
             if(LabourCost.getText().equals(""))
             {
             System.out.println("ERROR: Please enter an Labour Cost ");
             }
                else
             {
             System.out.println("ERROR: Labour Cost is not an integer");
             }
            }


      String actionCommand = e.getActionCommand();
     if(e.getSource() instanceof JButton)
    {
         if("AddJob".equals(actionCommand))
         addFJob();
     }

public  void addFJob()
{

        FixedRateJob job = new  FixedRateJob(Id.getText(), Customer.getText(), Paid.getText(),  Double.parseDouble(MaterialCost.getText()), Double.parseDouble(LabourCost.getText()));
        collection.addFJob(job);
        Id.setText("");
        Customer.setText("");
        Paid.setText("");
        MaterialCost.setText("");
        LabourCost.setText("");

}

At the moment the program clear the text field once the Addbutton has been pressed. I still want to keep inthis function but have the information that has been entered desplayed in the textArea

thank you
Halt123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
Ct\reate a new JTextArea to display the new job and ad that to your gui where you want it to appear
then in you actionlistener after you add the jab append the details to the new text area

// first clear it
ta.setText("");
ta.append("New Job:\n");
ta.append("ID: "+newjob.getID()+"\n");
ta.append("Customer: "+newjob.getCustomer()+"\n");
// similiar for other fields you want to append
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Halt123Author Commented:
I've started to write the code here is this the right place?

Id = new JTextField(10);
        Id.setHorizontalAlignment(JTextField.RIGHT);
        Id.addActionListener(this);
      displayArea.setText("");
      displayArea.append("New Job:\n");
      displayArea.append("ID: "+newjob.getID()+"\n");
      displayArea.append("Customer: "+newjob.getCustomer()+"\n");
                p2.add(Id);

But im not sure what to call newJob..
0
objectsCommented:
you would create and add your text area in your constructor making it a member variable. The same as u have done for the other fields.

And add the code to actually display the text in your action ;listener
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Halt123Author Commented:
like this:

                JTextArea displayArea;
      displayArea = new JTextArea(15, 11);
      displayArea.setText("");
      displayArea.append("New Job:\n");
               p4.add(displayArea);

              Id = new JTextField(10);
              Id.setHorizontalAlignment(JTextField.RIGHT);
              Id.addActionListener(this);
              displayArea.append("ID: "+AddJob.getID()+"\n");
              p2.add(Id);

      
0
Manikandan ThiagarajanSenior consultantCommented:
0
Halt123Author Commented:
ok ill take a look thank you
0
objectsCommented:
>    JTextArea displayArea;

make that member variable so you can access it in your action listener
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
0
CEHJCommented:
A JTable would seem a good way of doing this and would give you a better display
0
Halt123Author Commented:
Thank you for all your comments.
0
objectsCommented:
no worries :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.