Java Reference
In-Depth Information
Debugging Assignment
Find and fix the error in each line of code. Each line contains only one error.
Assume variables have been declared correctly.
1. public class myFrame extends ActionListener
2. for (int i = 0, i<10; i++)
3. myPad.setGridLayout(4,4);
4. add(myField, BorderLayout.TOP);
5. myButton.addActionListener;
6. Case 1:
7. myArray[i] = new Button(valueOf(i));
8. addSystem.exit(0);
9. myField.setEditable(“”);
10. add(“CENTER”, new Button(“Center”));
Programming Assignments
1 Coding a Choice Component
Figure 5-48 displays a drop-down list created using a Choice component.
Write the Java code to declare and construct the Choice component named
zoomChoice. Then, write the code to populate the component as shown.
2 What's My Color?
Figure 5-49 displays an interface with five option buttons in a Frame. When
clicked, each button changes the background color of the Frame. Perform the fol-
lowing steps to create the application.
FIGURE 5-48
FIGURE 5-49
1. Start TextPad. Create a block comment with your name, date, program name,
and purpose. Write the code for the class header. Name the file ColorButtons.
Save the program on the Data Disk as a Java source code file.
2. Construct an instance of a CheckboxGroup with five Checkboxes.
3. Write the constructor method for ColorButtons(). In that method, assign
FlowLayout as the layout manager. Use the add() method to add each of the
Checkboxes to the Frame and add the ItemListener to each Checkbox. Write
the code for the addWindowListener() method, as was done in the chapter.
(continued)
Search WWH ::




Custom Search