Java Reference
In-Depth Information
4. Enter a public class header for Freddie that extends Applet and implements
ItemListener.
5. Create each of the following components using a constructor:
sandwichPromptLabel, sandwichInputField, sizePromptLabel, catsupBox,
mustardBox, picklesBox, sizeGroup, smallBox, mediumBox, largeBox.
Set all the condiment Checkboxes to false. Set the first size Checkbox in the
CheckboxGroup to true and the other sizes to false.
6. Create an init() method by typing public void init() as the header and
adding an opening brace.
7. Set the background color of the applet window to red.
8. Enter add() methods for each of the components created in Step 5. Use an
addItemListener(this) for each of the boxes and buttons. Type the closing
braces for the init() method.
9. Type public void itemStateChanged(ItemEvent choice) as the
header of the itemStateChanged() method. Type an opening brace and clos-
ing brace to stub in the event.
10. Compile the program and fix any errors.
11. In TextPad, click New on the File menu and then enter the HTML code to
create an HTML host document to display the applet. Be sure to include the
beginning and ending HTML and APPLET tags. Use a width of 350 and a
height of 300.
12. Save the HTML host document on the Data Disk using the file name
Freddie.html.
13. Run the applet. Click each of the buttons and boxes. Notice the Checkboxes
toggle on and off, individually, while the grouped Checkboxes are mutually
exclusive.
14. Print a copy of the source code for your instructor.
15. As an extra credit assignment, code the itemStateChanged() method to print
out a confirmation dialog box of the customer's order.
6 Traffic Violations
You are serving an internship with the traffic court in the city where you live.
The clerks in the traffic court office want a simple application that will allow
them to enter the actual speed limit, the speed at which the offender was travel-
ing, and the number of previous tickets that person has received. The application
should provide interface options to allow users to calculate charges and exit the
application. The application should calculate and display how many miles over
the speed limit the offender was traveling, the cost of the speeding ticket, and
court costs. The program should calculate a charge of $20.00 for each mile per
hour over the speed limit. The program should calculate court costs beginning at
$74.80 for the first offense and increasing by $25.00 for each subsequent offense
up to the third offense (that will represent the maximum court cost).
Search WWH ::




Custom Search