Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Search the internet for information regarding the

Search the Internet for information regarding the interaction between web browser and web server using HTTPS from initial handshake to close of the session. Create a detailed drawing of the steps and also annotate each s ...

Sales bar chartwrite a program that asks the user to enter

Sales Bar Chart Write a program that asks the user to enter today's sales for 5 stores. The program should then display a bar graph comparing each store's sales. Create each bar in the bar graph by displaying a row of as ...

Suppose users share a 3 mbps link also suppose each user

Suppose users share a 3 Mbps link. Also suppose each user requires 150 kbps when transmitting, but each user transmits only 10 percent of the time. When circuit switching is used, how many users can be supported? For the ...

A street vendor is asking people to play a simple game you

A street vendor is asking people to play a simple game. You roll a pair of dice. If the sum on the dice is 10 or higher, you win $10. If you roll a pair of 1's, you win $59. Otherwise you lose $5. If the random variable ...

Question please read this instruction and section 5 and 6

Question: Please read this instruction, and section 5 and 6 in particular, CAREFULLY as it affects all future programming assignments. 1. Setup Android Studio Development Environment 1.1 Download necessary packages using ...

What is the purpose of load balancing i need full

What is the purpose of load balancing? (I need full explanation) I already know what load balancing is, I just need to know why we use it

Write a program to calculate the average temperature for

Write a program to calculate the average temperature for the year and determine the hottest month of the year. In your main method, the program should collect the user input of the average Fahrenheit temperatures for eac ...

In c languageread a double number as 2 digits after the

In C language: Read a double number as 2 digits after the decimal point. The number should have at least 6 digits BEFORE the decimal point. Extract all digits at even positions. Print them in reverse order. Extract all d ...

What is the prupose of adding nahco3 solution to dissolve

What is the prupose of adding NaHCO3 solution to dissolve the crude products in refinning process (Chemistry)

The current price of dumbas common stock is 25 per share

The current price of DUMBA's common stock is $25 per share. You plan on buying it today, holding it for 4 years, and then selling it. You anticipate receiving a dividend per share of $1.00 one year from today, $2.00 two ...

  • 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