Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

void is an invalid type for the variable actionperformed

adcf4bfa-5273-4c80-95e0-22be6df72098May 1 2015 — edited May 1 2015

I get an error in a program  "void is an invalid type for the variable actionperformed"

Here is the code of my program.

import java.awt.EventQueue;

import javax.swing.JFrame;

import java.awt.Label;

import java.awt.BorderLayout;

import java.awt.Button;

import java.awt.TextArea;

import java.awt.Choice;

import javax.swing.JRadioButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import javax.swing.JButton;

import javax.swing.JLabel;

import javax.swing.JTextPane;

import javax.swing.JTextField;

import javax.swing.ButtonGroup;

public class PayRoll{

public static final int NUM_PAY_EMP_RECORDS = 3;

  public static Employee[] employees = new Employee[NUM_PAY_EMP_RECORDS];

  public static PayRecord2[] payRecords = new PayRecord2[NUM_PAY_EMP_RECORDS];

  private JFrame frame;

  private JTextField textField_1;

  private final ButtonGroup buttonGroup = new ButtonGroup();

  private JTextField textField_2;

  private JTextField textField_3;

  private JTextField textField_4;

  private JTextField textField_5;

  private JTextField textField_6;

  private JTextField textField_7;

  private JTextField textField_8;

  private JTextField textField_9;

  private JTextField textField_10;

  private JTextField textField_11;

/**

  * Launch the application.

  */

  public static void main(String[] args) {

  EventQueue.invokeLater(new Runnable() {

  public void run() {

  try {

  PayRoll window = new PayRoll();

  window.frame.setVisible(true);

  } catch (Exception e) {

  e.printStackTrace();

  }

  }

  });

  }

/**

  * Create the application.

  */

  public PayRoll() {

  initialize();

  }

/**

  * Initialize the contents of the frame.

  */

  private void initialize() {

  frame = new JFrame();

  frame.setBounds(200, 400, 525, 750);

  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  frame.getContentPane().setLayout(null);

  JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("FullTime");

  buttonGroup.add(rdbtnNewRadioButton_1);

  rdbtnNewRadioButton_1.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent arg0) {

  }

  });

  rdbtnNewRadioButton_1.setBounds(83, 106, 143, 23);

  frame.getContentPane().add(rdbtnNewRadioButton_1);

  JRadioButton rdbtnNewRadioButton_2 = new JRadioButton("Hourly");

  buttonGroup.add(rdbtnNewRadioButton_2);

  rdbtnNewRadioButton_2.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent arg0) {

  }

  });

  rdbtnNewRadioButton_2.setBounds(83, 141, 143, 23);

  frame.getContentPane().add(rdbtnNewRadioButton_2);

  JTextPane textPane = new JTextPane();

  textPane.setBounds(58, 33, 1, 16);

  frame.getContentPane().add(textPane);

  JLabel lblEmployee = new JLabel("Employee:");

  lblEmployee.setBounds(8, 6, 70, 16);

  frame.getContentPane().add(lblEmployee);

  JLabel lblId = new JLabel("ID:");

  lblId.setBounds(5, 33, 30, 16);

  frame.getContentPane().add(lblId);

  textField_1 = new JTextField();

  textField_1.setBounds(33, 27, 42, 28);

  frame.getContentPane().add(textField_1);

  textField_1.setColumns(10);

  JLabel lblFirstName = new JLabel("First Name: ");

  lblFirstName.setBounds(98, 33, 77, 16);

  frame.getContentPane().add(lblFirstName);

  textField_2 = new JTextField();

  textField_2.setBounds(172, 27, 98, 28);

  frame.getContentPane().add(textField_2);

  textField_2.setColumns(10);

  JLabel lblLastName = new JLabel("Last Name: ");

  lblLastName.setBounds(304, 33, 77, 16);

  frame.getContentPane().add(lblLastName);

  textField_3 = new JTextField();

  textField_3.setBounds(385, 27, 98, 28);

  frame.getContentPane().add(textField_3);

  textField_3.setColumns(10);

  JLabel lblEmployeeStatus = new JLabel("Employee Status:");

  lblEmployeeStatus.setBounds(10, 76, 111, 16);

  frame.getContentPane().add(lblEmployeeStatus);

  JButton btnAddEmployee = new JButton("Add Employee");

  btnAddEmployee.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent e) {

  actionPerformed(e);

  

  }

  });

  btnAddEmployee.setBounds(189, 176, 117, 29);

  frame.getContentPane().add(btnAddEmployee);

  public void actionPerformed(ActionEvent e){  //I get the error on this line

  String fullName = textField_2.getText();

  String lastName = textField_3.getText();

  String eID      = textField_1.getText();

  }

  JLabel lblPayPeriod = new JLabel("Pay Period:");

  lblPayPeriod.setBounds(10, 209, 91, 16);

  frame.getContentPane().add(lblPayPeriod);

  JLabel lblId_1 = new JLabel("ID:");

  lblId_1.setBounds(5, 251, 22, 16);

  frame.getContentPane().add(lblId_1);

  textField_4 = new JTextField();

  textField_4.setBounds(33, 243, 42, 28);

  frame.getContentPane().add(textField_4);

  textField_4.setColumns(10);

  JLabel lblStartDate = new JLabel("Start Date:");

  lblStartDate.setBounds(83, 252, 76, 16);

  frame.getContentPane().add(lblStartDate);

  textField_5 = new JTextField();

  textField_5.setBounds(165, 246, 87, 28);

  frame.getContentPane().add(textField_5);

  textField_5.setColumns(10);

  JLabel lblEndDate = new JLabel("End Date:");

  lblEndDate.setBounds(294, 251, 61, 16);

  frame.getContentPane().add(lblEndDate);

  textField_6 = new JTextField();

  textField_6.setBounds(365, 245, 91, 28);

  frame.getContentPane().add(textField_6);

  textField_6.setColumns(10);

  JLabel lblPayRecord = new JLabel("Pay Record:");

  lblPayRecord.setBounds(10, 295, 73, 16);

  frame.getContentPane().add(lblPayRecord);

  JLabel lblMonthlyIncome = new JLabel("Monthly Income ");

  lblMonthlyIncome.setBounds(102, 322, 111, 16);

  frame.getContentPane().add(lblMonthlyIncome);

  textField_7 = new JTextField();

  textField_7.setBounds(212, 316, 76, 28);

  frame.getContentPane().add(textField_7);

  textField_7.setColumns(10);

  JLabel lblNoMonths = new JLabel("No. Months");

  lblNoMonths.setBounds(305, 322, 76, 16);

  frame.getContentPane().add(lblNoMonths);

  textField_8 = new JTextField();

  textField_8.setBounds(385, 316, 76, 28);

  frame.getContentPane().add(textField_8);

  textField_8.setColumns(10);

  JLabel lblId_2 = new JLabel("ID:");

  lblId_2.setBounds(5, 368, 22, 16);

  frame.getContentPane().add(lblId_2);

  JLabel lblPayHours = new JLabel("Pay Hours");

  lblPayHours.setBounds(138, 394, 70, 16);

  frame.getContentPane().add(lblPayHours);

  textField_9 = new JTextField();

  textField_9.setBounds(212, 388, 70, 28);

  frame.getContentPane().add(textField_9);

  textField_9.setColumns(10);

  JLabel lblPayRate = new JLabel("Pay Rate");

  lblPayRate.setBounds(307, 394, 61, 16);

  frame.getContentPane().add(lblPayRate);

  textField_10 = new JTextField();

  textField_10.setBounds(386, 388, 70, 28);

  frame.getContentPane().add(textField_10);

  textField_10.setColumns(10);

  JButton btnAddRecord = new JButton("Add Record");

  btnAddRecord.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent e) {

  }

  });

  btnAddRecord.setBounds(189, 468, 117, 29);

  frame.getContentPane().add(btnAddRecord);

  textField_11 = new JTextField();

  textField_11.setBounds(6, 525, 513, 115);

  frame.getContentPane().add(textField_11);

  textField_11.setColumns(10);

  JButton btnClose = new JButton("Close");

  btnClose.addActionListener(new ActionListener() {

  public void actionPerformed(ActionEvent arg0) {

  System.exit(0);

  }

  });

  btnClose.setBounds(208, 652, 87, 29);

  frame.getContentPane().add(btnClose); 

  

    //String eID = textField_1.getText();

  }

}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2015
Added on May 1 2015
1 comment
3,199 views