title: ActionListener not recognizing variables from main class
body: <p>I am trying to create a GUI payroll calculator for a Java class I am taking.  The requirements were that it must take the user inputs (one using a JComboBox), calculate the weekly pay and add the results to a JTable.  The user should be able to continue calculating for other employees and have an exit button.  I created the GUI in the main class and need two ActionListeners, one to exit and one to calculate and add to the JTable.</p>
  
  <p>My problem is that when I start working on the calculate ActionListener, it is not recognizing the variables I set in the main class.  I have tried making them public, using the main class name DOT variable name (PayrollCalc.empName), initializing them and nothing seems to work. The code is not complete, as I have not even started to add to the JTable until I can get the actual calculations done first.  Does anyone have any suggestions?</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  import java.awt.event.*;
  
  public class PayrollCalc {
  
      public static void main(String[] args) {
  
          //Declare variables used
          String empName = null, entDept = null, calcdPay = null;
          String[] empDept = {"Marketing","IT","Accounting","Development","Payroll","Facilities"};
          String columnNames[] = {"Name","Department","Pay Check"};
          String dataValues [][] = {
                  {empName,entDept,calcdPay}
          };
  
          double wrkHours = 0;
          double empRate = 0;
          double wklyPay = 0;
  
          //Create JTable and scrollPane for output
          JTable table;
          JScrollPane scrollPane;
          table = new JTable (dataValues,columnNames);
          scrollPane = new JScrollPane(table);
  
          //Create JFrame object with title
          JFrame frame = new JFrame("Employee Payroll Calculator");
  
          //Create combo box for department choices
          JComboBox combo = new JComboBox(empDept);
          JTextField nameField = new JTextField(15);
          JTextField hourField = new JTextField(10);
          JTextField rateField = new JTextField(10);
  
          //Create JLables for input fields
          JLabel nameLbl = new JLabel ("Name:");
          JLabel hourLbl = new JLabel ("Hours:");
          JLabel rateLbl = new JLabel ("Rate:");
          JLabel deptLbl = new JLabel ("Department:");
  
          //Create buttons for ActionListners
          JButton exitButton= new JButton("Exit");
          exitButton.addActionListener(new exitApp());
          exitButton.setSize(5,5);
  
          JButton calcButton= new JButton("Calculate");
          calcButton.addActionListener(new calcApp());
          calcButton.setSize(5,5);
  
          //Create panels
          Panel panel1 = new Panel();
          panel1.add(nameLbl);
          panel1.add(nameField);
          panel1.add(deptLbl);
          panel1.add(combo);
          panel1.add(hourLbl);
          panel1.add(hourField);
          panel1.add(rateLbl);
          panel1.add(rateField);
          panel1.add(rateField);
  
          Panel panel2 = new Panel();
          panel2.add(calcButton);
  
          Panel panel3 = new Panel();
          panel3.add(calcButton);
          panel3.add(exitButton);
  
          Panel panel4 = new Panel();
          panel4.add(scrollPane, BorderLayout.CENTER);
  
  
          //creates the frame
          frame.setSize(950,200);
          frame.add(panel1,BorderLayout.NORTH);
          frame.add(panel2);
          frame.add(panel3, BorderLayout.SOUTH);
          frame.add(panel4);
          frame.setVisible(true);
  
  
  
      }
      //ActionListner for Exit button
      static class exitApp implements ActionListener
      {
          public void actionPerformed(ActionEvent e)
          {
              System.exit(0);
          }
      }
      //ActionListner for Calculate button
      static class calcApp implements ActionListener
      {
          public void actionPerformed(ActionEvent c)
          {
              empName = nameField.getText();
              entDept = combo.getName();
              wrkHours = Double.parseDouble(hourField.getText());
              empRate = Double.parseDouble(rateField.getText());
              wklyPay = wrkHours * empRate;
              calcdPay = new Double(wklyPay).toString();
          }
  
      }
  
  }
  </code></pre>