You are on page 1of 3

Working with Strings Assignment 14 (20 points): Working with Strings

You are to complete the Java program called RegistrationForm. The GUI already has the labels and textfields for name, address, city, state and zip completed.

Once the form has been completed by user, the submit button is pressed. The ActionListener listens to the submit button and when that button is pressed the actionPerformed method is executed. Since there are 2 buttons (submit and clear) on this form, we need to distinguish between the actions that should be taken when the user clicks on the submit button and clicks on the clear button. To do this, we need to check the event that is passed into the actionPerformed method to see if it equals Submit (submit button) or Clear (clear button). If the event is the submit button, then we need to have if statements that one-by-one calls methods that test the accuracy of the data.

Working with Strings

The following if statement causes each of the methods to be executed: if (checkName() & checkAddress() & checkCity() & checkState() & checkZip() ) Note: The & is used instead of the && (short-circuit AND) because you want all methods to be executed even if the first method returns false. You should see all the errors at one time. Please see the program for method descriptions. If the event is the clear button, then the text should be cleared from the text boxes and the label foreground colors should be set at black.

You are to do add the following: Add labels and textfields for phone, email, password, and retype password. Adjust the GUI any way that you like as long as it looks good. DO NOT delete the labels and textfields that I have already created for you. (4 points) Adjust the if statement in actionPerformed method to cause execution of the methods: checkPhone, checkEmail and checkPassword. (1 point) The checkPhone method needs to be added to program. This method should test that the user has entered the first 3 digits of the phone as 972 or 214. If the first 3 digits of phone number are 972 or 214, then the phone label foreground should be set to black. If

Working with Strings


the first 3 digits of the phone are NOT 972 and NOT 214, then the phone label foreground should be set to red. You should use the substring or startsWith method to do this. Do not use parenthesis when entering the phone number into the field. (4 points) The checkEmail method needs to be added to program. This method should test that the user has entered a @ sign somewhere in the email field. If there is no @ in the email address, then the email label foreground should be set to red. (4 points) The checkPassword method needs to be added to program. This method should check the text in the password textfield vs. the text in the retype password textfield. If both of these passwords are equal, then both labels foregrounds (password and retype password) should be set to black. If these passwords are not equal, then both labels foregrounds should be set to red. (4 points) Once all of the methods have been executed and NO errors have occurred, a label saying "Thank you for your registration." should appear. If there are any errors in any of the items, then a label saying "Please correct items in red" should appear. (1 point) Make sure that the clear button clears the new fields and sets the foreground color of the labels to black. (2 points)

You might also like