The user inputs date of birth of an employee, but the task says you have to validate the entries.
What I want the application to display is an error when the user inputs day of birthdate as 33 or something as there is no such day in B.O.D.
Also, when the user clicks save, the data in the textfields should be saved into an arraylist. And when the user clicks print, the data that is saved in the arraylist should be displayed as previous information.
public class JavaGUI {
ArrayList<JavaMethods> arl10 = new ArrayList<JavaMethods>();
ArrayList<JavaMethods> arl11 = new ArrayList<JavaMethods>();
JFrame frame;
JPanel panel;
JLabel labelA = new JLabel("Employee Information");
JLabel labelB = new JLabel("Employee Birthdate");
JLabel label1 = new JLabel("Employee Name:");
JTextArea txt1 = new JTextArea(" ");
JLabel label2 = new JLabel("Employee Address:");
JTextArea txt2 = new JTextArea(" ");
JLabel label3 = new JLabel("Employee Age:");
JTextArea txt3 = new JTextArea(" ");
JLabel label4 = new JLabel("Day:");
JTextArea txt4 = new JTextArea(" ");
JLabel label5 = new JLabel("Month:");
JTextArea txt5 = new JTextArea(" ");
JLabel label6 = new JLabel("Year:");
JTextArea txt6 = new JTextArea(" ");
JButton btn1 = new JButton("Clear");
JButton btn2 = new JButton("Save");
JButton btn3 = new JButton("Print");
JRadioButton male = new JRadioButton("Male");
JRadioButton female = new JRadioButton("Female");
ButtonGroup g1 = new ButtonGroup();
ActionListener act1 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
txt1.setText(" ");
txt2.setText(" ");
txt3.setText(" ");
txt4.setText(" ");
txt5.setText(" ");
txt6.setText(" ");
}
};
ActionListener act2 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
int day = Integer.parseInt(txt4.getText());
if(day <= 32) {
JOptionPane.showMessageDialog(frame, "Employee Information has been saved, Click PRINT to show them!");
JavaMethods arl10 = new JavaMethods(txt1.getText().trim(), txt2.getText().trim(), male.getText(),Integer.parseInt(txt3.getText().trim()), Integer.parseInt(txt4.getText().trim()),Integer.parseInt(txt5.getText().trim()), Integer.parseInt(txt6.getText().trim()));
arl11.add(arl10);
}
else {
System.out.println("wrong day");
}
}
catch(NumberFormatException ex)
{
System.out.println("Exception : "+ex);
}
}
};
ActionListener act3 = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
System.out.println(arl11);
JavaMethods arl10 = new JavaMethods(txt1.getText().trim(), txt2.getText().trim(), female.getText(),
Integer.parseInt(txt3.getText().trim()), Integer.parseInt(txt4.getText().trim()),
Integer.parseInt(txt5.getText().trim()), Integer.parseInt(txt6.getText().trim()));
arl11.add(arl10);
System.out.print("Previously Stored Information" + " " + arl11);
System.out.println();
System.out.println(arl10.toString());
}
catch (Exception e1) {
System.out.println(
"Unable to perform the task, Please make sure you have entered the right DataType, Or make sure you have filled all the blanks.");
}
}
};
public JavaGUI() {
frame = new JFrame();
panel = new JPanel();
frame.setPreferredSize(new Dimension(500, 500));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("HR System");
btn1.addActionListener(act1);
btn2.addActionListener(act2);
btn3.addActionListener(act3);
panel.add(labelA);
panel.add(label1);
panel.add(txt1);
panel.add(label2);
panel.add(txt2);
panel.add(label3);
panel.add(txt3);
panel.add(labelB);
panel.add(label4);
panel.add(txt4);
panel.add(label5);
panel.add(txt5);
panel.add(label6);
panel.add(txt6);
g1.add(male);
g1.add(female);
panel.add(btn1);
panel.add(btn2);
panel.add(btn3);
panel.add(male);
panel.add(female);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}