Create a constructor method named checkerboard

Assignment Help Computer Engineering
Reference no: EM131936969

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.

Reference no: EM131936969

Questions Cloud

What is the difference between the ecf and the icf : What is the difference between the ECF and the ICF? Would you classify blood plasma as ICF or ECF?
Write a java program that allows you to enter your grades : Write a Java program that allows you to enter your grades in this course into an array of floats. Display the grades and the resulting average.
List a muscle that is a prime mover : List a muscle that is a prime mover/agonist for turning the head laterally
What would the interest rate be on treasury bond : Assume that liquidity and maturity risk premiums are zero. The annual interest rate on a two-year Treasury bond is 10 percent, whereas the annual interest rate.
Create a constructor method named checkerboard : Create a constructor method named Checkerboard(), which includes code that sets the Frame layout manager to Border Layout.
Term paper caesar the general and leader : Topic is caesar the general and Leader - Your paper shows not only the thoughtful reading and research that you've put into your topic
What amount would the healthcare system need to invest : Assume a large healthcare system has just approved a $355,000 annual (per year) bonus to retain its top cardiac surgeon.
Clinical significance of urinalysis indicating cloudy urine : Define specific gravity as it relates to urine and state the clinical significance of a urinalysis indicating cloudy urine
Find the value of gillette stock : Assume Gillette Corporation will pay an annual dividend of $0.66 one year from now. Analysts expect this dividend to grow at 11.7% per year thereafter.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd