Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92775625

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As