title: Make JButton insert text from JTextField into variables?
body: <p>I'm trying to write a program that will take text in a JTextField and put it into variables I've declared when I press a JButton. I need to calculate weekly pay for a school project, but that only requires the console, I'm doing the GUI for my own fun. I'm trying to get it so when I hit 'calc' it'll take the imputs from id, rh, oh, hp, etc and calculate weekly pay (wp), which will then be printed on the right column next to the calc button.</p>
  
  <pre><code>//the calculations aren't complete yet until I finish the GUI
  
  public class Weekly_Pay 
  {
  
  public static void calculations(String[] args) 
  {
  
  Scanner imput = new Scanner(System.in);
  
  System.out.println("ID number: ");
  int employeeId = imput.nextInt();
  
  System.out.println("Hourly Wage: ");
  Double hourlyWage = imput.nextDouble();
  
  System.out.println("Regular Hours: ");
  double regularHours = imput.nextDouble();
  
  System.out.println("Overtime Hours: ");
  double overtimeHours = imput.nextDouble();
  
  double overtimePay = round(overtimeHours * (1.5 * hourlyWage));
  double regularPay  = round(hourlyWage * regularHours);
  
  double weeklyPay = regularPay + overtimePay;
  
  System.out.println("Employee ID Number:" + employeeId);
  System.out.printf("Weekly Pay: " + "$%.2f\n", weeklyPay);
  
  }
  
  public static double round(double num) 
  {
  
  // rounding to two decimal places
  num *= 100;
  int rounded = (int) Math.round(num);
  return rounded/100.0;
  
  }
  
  
  public static void main(String[] args) 
  {
  
  JFrame window = new JFrame();
  window.setTitle("Weekly Pay");
  window.setSize(350, 200);
  window.setResizable(false);
  window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  Color lGray = new Color(209, 209, 209);
  
  JPanel panel = new JPanel();
  GroupLayout layout = new GroupLayout(panel);
  panel.setBackground(lGray);
  panel.setLayout(layout);
  layout.setAutoCreateGaps(true);
  layout.setAutoCreateContainerGaps(true);
  
  JTextField idEntry = new JTextField(); //where the user imputs their ID
  JTextField hwEntry = new JTextField(); //where the user imputs their hourly wage
  JTextField rhEntry = new JTextField(); //where the user imputs their regular hours
  JTextField ohEntry = new JTextField(); //where the user imputs their overtime hours
  
  JLabel id = new JLabel("ID Number");
  JLabel hw = new JLabel("Hourly Wage");
  JLabel rh = new JLabel("Regular Hours");
  JLabel oh = new JLabel("Overtime Hours");
  JButton calc = new JButton("Calculate");
  JLabel wp = new JLabel(" Weekly Pay: $" + "$%.2f\n", weeklyPay);
  
  GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();    
  hGroup.addGroup(layout.createParallelGroup().
             addComponent(id).addComponent(hw).addComponent(rh).addComponent(oh).addComponent(calc));
  hGroup.addGroup(layout.createParallelGroup().
    addComponent(idEntry).addComponent(hwEntry).addComponent(rhEntry).addComponent(ohEntry).addComponent(wp));
  layout.setHorizontalGroup(hGroup);
  
  GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();    
  vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
      addComponent(id).addComponent(idEntry));
  vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
      addComponent(hw).addComponent(hwEntry));
  vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
      addComponent(rh).addComponent(rhEntry));
  vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
      addComponent(oh).addComponent(ohEntry));
  vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
      addComponent(calc).addComponent(wp));
  layout.setVerticalGroup(vGroup);
  
  window.add(panel);
  window.setVisible(true);
  
  }  
  }
  </code></pre>