Create a constructor method named checkerboard which


Problem

Using a Component Array and Counter-Controlled Loop

You are tutoring programming students and want an application to demonstrate arrays and looping structures. You decide to create a panel containing an array of 16 Text Field components that change color to correspond with the start, stop, and step values entered by the user and to create a looping structure that allows the student to specify how many times the loop statements will be executed. Perform the following tasks to create the Checkerboard Array application shown in Figure 5-50a. When the user enters the start, stop, and step fields and then clicks the Go button, the results display as shown in Figure 5-50b.

1. Start Text Pad. Create a block comment with your name, date, program name, and purpose.

2. Import the java.awt.* and awt.event.* packages.

3. Create a class named Checkerboard that extends the Frame and implements the ActionListener. Save the program on the Data Disk as a Java source code file with the file name Checkboard.java.

4. Declare variables for the following components included in the Frame:

a. an array of 16 Text Field components

b. a Panel to hold the array

c. three individual Text Field components

d. three int variables to receive the start, stop, and step input data

e. three Labels to display Start, Stop, and Step

f. a Go button and a Clear button

g. a Panel to hold the three fields and the Labels

h. a Panel to hold the two buttons

5. Create a constructor method named Checkerboard(), which includes code that:

a. constructs each of the components declared above and sets the start, stop, and step variables to zero

b. sets the Frame layout manager to Border Layout

c. writes a for loop to loop the array and set each of the 16 Text Field components in that array so they cannot be edited; within the same loop, set each Text Field component's text to match the loop increment

d. sets the upper Panel to Grid Layout 4 by 4 and sets the lower Panel to Grid Layout 2 by 3

e. adds the components to their respective Panels

f. uses the add Action Listener() method to make the button clickable

g. places the panels in the Frame using the appropriate border area

h. enters the add Window Listener() method as described in the chapter

6. To make the buttons work, code an action Performed() method as follows:

a. enter the method header, using the identifier, e, as an argument.

b. Write an if statement to test for Go or Clear. If the agument is Go, convert the data from the input fields to ints using the get Text() method along with the parseInt() method. Store the result in the variables declared for that purpose in Step 4 above. If the argument is Clear, or integers are not entered properly, set all colors back to white and clear the input fields.

c. Write a loop that goes through the array setting every background color to a darker color, such as magenta.

d. Write a loop based on the user input values. Each time the loop is executed, change the background color to a lighter color, such as yellow.

7. Write a main method that creates an instance of the Checkerboard Frame.

a. Set the bounds of the Frame to 50, 100, 300, and 400.

b. Set the title bar caption as Checkerboard Array.

c. Use the set Visible() method to display the application Frame during execution.

8. Save the file on the Data Disk using the same file name.

9. Compile the source code. Fix any errors and recompile, if necessary.

10. Run the application several times, trying different numbers for the Start, Stop, and Step input values. Remember that the array has a length of 16, so the highest allowable stop value is 15.

11. Print a copy of the source code for your instructor.

12. For extra credit, write code to display a JOptionPane error dialog box if the user enters a value greater than 15.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Create a constructor method named checkerboard which
Reference No:- TGS02732441

Expected delivery within 24 Hours