Java Reference
In-Depth Information
b. sets the Frame layout manager to BorderLayout
c. writes a for loop to loop the array and set each of the 16 TextField
components in that array so they cannot be edited; within the same loop,
set each TextField component's text to match the loop increment
Hint : Use the setEditable() and setText() methods.
d. sets the upper Panel to GridLayout 4 by 4 and sets the lower Panel to
GridLayout 2 by 3
e. adds the components to their respective Panels
f. uses the addActionListener() method to make the button clickable
g. places the panels in the Frame using the appropriate border area
h. enters the addWindowListener() method as described in the chapter
6. To make the buttons work, code an actionPerformed() 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 getText() 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 exe-
cuted, 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 setVisible() 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.
4 Using an Applet to Search an Array
Many e-commerce Web sites and intranets require that users enter a correct login
ID and password in order to access data from the site. You recently have taken a
work-study job in the Computer Administration department and have been asked
to finish a login applet started by a previous student. The applet will ask the user
for an ID and password. Once the user clicks the Login button, the applet will
search through an array of IDs and passwords for verification. The applet
(continued)
Search WWH ::




Custom Search