linking GUI with program

Dear experts,

I have written a GUI application that has buttons/labels and text boxes on it. I have also written a program that is made to run in the comand prompt.This program uses several different classes to run and it allows the user to add info, find info and do other things aswell.

However i am unsure how I am meant to link the two programs together.

If you would like me to post the code that I have please let me know:)

Thank you in advance.
Halt123Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

CEHJCommented:
Possibly a good idea to post the code, but please post a link to it if possible
Halt123Author Commented:
How would I post a link to it?
CEHJCommented:
In public webspace of use http://pastebin.com

You basically need to have public set methods to set the fields from input
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Mick BarryJava DeveloperCommented:
You can use the classes from your command line app in the same way you use any classes.
So just use them in your GUI as you need them.
Halt123Author Commented:
Ok i will give that a go and get back to you in a bit.

Thank you
Halt123Author Commented:
When I run the GUI with the same class in my program from the command line it brings up the error:

The error is
JobApplication.java:187: cannot find symbol
symbol  : constructor Job(javax.swing.JTextField,javax.swing.JTextField,javax.swing.JTextField,javax.swing.JTextField,javax.swing.JTextField)
location: class Job
   Job job = new  Job(Id, Customer, Paid, MaterialCost, LabourCost);

However with the program that runs from the command line it compiles are doesnt seem to have a problem.
Mick BarryJava DeveloperCommented:
does Job expects strings?
If so use:

Job job = new  Job(Id.getText(), Customer.getText(), Paid.getText(), MaterialCost.getText(), LabourCost.getText());
Mick BarryJava DeveloperCommented:
If you need an int you use something like:

int id = Integer.parseInt(Id.getText());

you'll find other conversions here:

http://www.objects.com.au/java/conversions.do
Halt123Author Commented:
Its compiled
thank you

is there a way to check that it is working in the GUI?
Mick BarryJava DeveloperCommented:
maybe add some debug println() to your Job class to see what values it gets
CEHJCommented:
If you don't already have a toString method in Job, provide an implementation that prints the fields:

System.out.println(job);

will show everything (where 'job' is the appropriate reference)
Halt123Author Commented:
Ah ok thank you

one last question:

Is there a way for the fields to empty once the user has clicked add job

the code for add job is:

public void actionPerformed(ActionEvent e)
{
                 String text1 = Id.getText();
       String text2 = Customer.getText();
       String text = Paid.getText();
                 Double.parseDouble(MaterialCost.getText());
        Double.parseDouble(LabourCost.getText());



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

}
      

public  void addFJob()
{

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

}
CEHJCommented:
You need to call setText("");

on your text fields
Mick BarryJava DeveloperCommented:
public  void addFJob()
{

     Job job = new  Job(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("");


}
Halt123Author Commented:
I've tried writing the code but it doesnt clear them.
Halt123Author Commented:
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 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

      //Place panels on frame
      getContentPane().add(p1, "South");
      getContentPane().add(p2, BorderLayout.EAST);
      getContentPane().add(p3, BorderLayout.CENTER);
      
      
               //panel P1 to hold the buttons
               JButton AddJob = new JButton("AddJob");
               AddJob.addActionListener(this);
              p1.add(AddJob);
           
                 JButton FindJob = new JButton("Find Job");
                 FindJob.addActionListener(this);
       p1.add(FindJob);

                 JButton Calulate = new JButton("Calulate");
                 AddJob.addActionListener(this);
       p1.add(Calulate);

            
          //Panel2 to hold text
         //creating a ID Textfield
         TextField Id;
         Id = new JTextField(10);
         Id.setHorizontalAlignment(JTextField.RIGHT);
         Id.addActionListener(this);
         p2.add(Id);

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

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

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



             //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);

                       //making the menu
                      JMenuBar bar = new JMenuBar();
                      setJMenuBar(bar);
                      JMenu app = new JMenu("Application");
                      bar.add(app);
                     JMenu helpMenu = new JMenu("Help");
                     bar.add(helpMenu);

                     JMenu actionappsubmenu = new JMenu("Action");
                      app.add(actionappsubmenu);
                      actionappsubmenu.addActionListener(this);


                       actionappsubmenu.add(new JMenuItem("AddJob"));
                       actionappsubmenu.add(new JMenuItem("FindJob"));
                       actionappsubmenu.add(new JMenuItem("Calulate"));

                       JMenuItem exitApp = new JMenuItem("Exit");
                       app.add(exitApp);
                       exitApp.addActionListener(this);
                       app.addSeparator();
                      //Adds short cuts
                       exitApp.setMnemonic(KeyEvent.VK_E);
                       KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.ALT_MASK);
                        exitApp.setAccelerator(key);


            

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


                 
   }
   public void actionPerformed(ActionEvent e)
      
 {
                 String text1 = Id.getText();
       String text2 = Customer.getText();
       String text = Paid.getText();
                 Double.parseDouble(MaterialCost.getText());
        Double.parseDouble(LabourCost.getText());



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

       
      if(e.getSource() instanceof JMenuItem)
      if("FindJob".equals(actionCommand))
      findFJob();

}
      

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("");

}


public  Job findFJob()
{
        return collection.findFJob(Id.getText());
}

      
public static void main(String args[])
 
 {
String lookAndFeel =
 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
       try
      {
           UIManager.setLookAndFeel(lookAndFeel);
        }
           catch (Exception e)
       {
          e.printStackTrace();
        }

            new JobApplication();
  }
}

I've posted the code above if that helps... :)

thank you
Mick BarryJava DeveloperCommented:
delete the following lines from your constructor:

     JTextField Id;
     JTextField Customer;
     JTextField Paid;          
     JTextField MaterialCost;
     JTextField LabourCost;

They are shadowing the member variables
Halt123Author Commented:
I've changed what u suggested but its still not refreshing
Halt123Author Commented:
Do i need to add mouselisteners in to the program. If so how do I go about doing it?
CEHJCommented:
No.  You've only got buttons by the looks. The following:

>>
            if (e.getSource() instanceof JMenuItem)
                  if ("AddJob".equals(actionCommand))
                        addFJob();
>>

should be

            if (e.getSource() instanceof JButton)
                  if ("AddJob".equals(actionCommand))
                        addFJob();

Also, you clear the text from some of the fields before you create the Job. This will give you errors

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:
Thank you it works now

I will split the points between you and objects as you both deserve them :)
CEHJCommented:
OK - glad i could help
CEHJCommented:
:-)
Mick BarryJava DeveloperCommented:
no worries :)
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.