java

3. (40) A Java file, EmployeeFrame.java, which defines Employee information is attached to this exam. It was written assuming
EmployeeFrame // EmployeeFrame.java public class EmployeeFrame extends JFrame ( public Employee employee; private final 3Text
aclorr EnployeefFrane 2register eveet handlers Texteteldandler textHandler new TexEFieldHandler()7 JastNaneTextField.adAction
EmployeeFrame //added code #4 System.out.println ( hourlyEmployee.toString( ); } } // end class EmployeeFrame 3. (40) A Java file, EmployeeFrame.java, which defines Employee information is attached to this exam. It was written assuming that GUI for entering a S Employee record only has a last name and a first name as an fields. You need to add code to handle two additional fields: ssn (social security number as a String) and salary (as already been added to the definition of the Employee class. The four areas that will need the code you must add are commented through //Added code #4. Write the necessary code for these areas, labeling each block of code with the proper area name. double). Assume they have a //Added code #1 as EmployeeFrame // EmployeeFrame.java public class EmployeeFrame extends JFrame ( public Employee employee; private final 3TextField lastNameText Field; // text field with set size private final JTextField firstName Text Field ; // text field with set size private final JLabel lastNameLabel; // text field with set size private final JLabel firstNameLabel; // text field with set size private final JButton printButton; // button to print entered data //EmployeeFrame constructor adds JTextEields to JFrame public EmployeeFrame() f super(“Hourly Employee Data”): setLayout (new FlowLayout ()); // construct lastNameTextField lastNameTextField new JTextField (24); lastNameLabel- new JLabel(“Last Name: “); // label lastNameLabel.setLabelFor ( last NameText Field ) ; add(lastName Label) ; add(lastNameText Field ); // add lastNameText Field to OFrame // construct firstName Text Field firstNameText Field new JTextField ( 24) ; firstNameLabel new JLabel ( “First Name: “); // label firstNameLabel.setLabelFor (firs tNameText Field ) ; add(firstNameLabel); add(firstNameText Field); // add firstNameText Field to JFrame // Added code #1 /1create new ButtonHandler for button event handling printButton new JButton (“Print”) ; ButtonHandler buttonHandler add(printButton); = new ButtonHandler (); Page 1 aclorr EnployeefFrane 2register eveet handlers Texteteldandler textHandler new TexEFieldHandler()7 JastNaneTextField.adActiontistener(textHandler); firstNaneTextField. addActiongistener(textHandler) /added code #2 printtutton, addactiont istener(buttonhandler) 1 end Emploveeframe constructor U private inner class for event hand1ing private class TextFieldHandler implements ActionListener process textfield events Override public void actionPerformed(ActionEvent event) user pressed Enter in 3TextField lastName TextField if (event.getSource () lastName TextField) employee.lastNane event.getActionCommand) I user pressed Enter in JTextField firstNameTextField else if (event.getSource() –firstName Text Field) employee. firstName event.getActionCommand(); //added code #3 } // end private inner class TextFieldHandler // er class for button event handling privato class ButtonHandler implements ActionListener //handle button event Override public void actionPerformed (Action Event event) employee = new Employee lastNameTextField . getText ( ) , firstNameText Field . get Text ( ), Page 2 EmployeeFrame //added code #4 System.out.println ( hourlyEmployee.toString( ); } } // end class EmployeeFrame



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *