(Fuzzy Dice Order Form Application) Write an application that allows users to pro- cess orders for fuzzy dice as shown in Fig. 7.30. The application should calculate the total price of the order, including tax. JTextFields for inputting the order number, the customer name and the shipping address are provided. Initially, these fields contain text that describes their purpose. If the user does not modify this text, a message dialog is displayed. Provide JCheckBoxes for selecting the fuzzy-dice color and JTextFields for inputting the quantities of fuzzy dice to order. If the user does not select any of the fuzzy-dice JCheckBoxes, a mes- sage dialog is displayed. The application should also contain a JButton that, when clicked, calculates the subtotals for each typ
```
a) Copying the template to your working directory. Copy the C:Examples Tutorial07ExercisesFuzzyDiceOrderForm directory to your C:SimplyJava directory.
b) Opening the template file. Open the FuzzyDiceOrderForm.java file in your text editor.
c) Customizing the JCheckBoxes. In line 137 set the bounds (10, 227, 93, 21) and text
(White/Black) properties of whiteTypeJCheckBox. In line 143 set the bounds (10,
252, 88, 21) and text (Red/Black) properties of redTypeJCheckBox.
d) Coding the calculateJButtonActionPerformed method. Code should be placed in the calculateJButtonActionPerformed method, which begins in line 283. In line
298, replace the keyword true with an expression that will return true if white- TypeJCheckBox has been selected. On line 305 replace keyword true with an expres- sion that will return true if redTypeJCheckBox has been selected. These if statements should now calculate subtotals for each type of dice if that type of dice has been
```
1 // FuzzyDiceOrderForm.java
2 // This application calculates the total cost of a
3 // purchase order for different colored fuzzy dice.
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.text.*;
7 import javax.swing.*;
8
9 public class FuzzyDiceOrderForm extends JFrame
10 {
11 // JLabel that displays header on application window
12 private JLabel fuzzyDiceJLabel;
13
14 // JLabel and JTextField for order number
15 private JLabel orderNumberJLabel;
16 private JTextField orderNumberJTextField;
17
18 // JLabel and JTextField for user's name
19 private JLabel nameJLabel;
20 private JTextField nameJTextField;
21
22 // JLabel and JTextFields for user's address
23 private JLabel addressJLabel;
24 private JTextField addressJTextField1;
25 private JTextField addressJTextField2;
26
27 // JLabel and JCheckBoxes for die types
28 private JLabel typeJLabel;
29 private JCheckBox whiteTypeJCheckBox;
30 private JCheckBox redTypeJCheckBox;
31
32 // JLabel and JTextFields for die quantities
33 private JLabel quantityJLabel;
34 private JTextField whiteQuantityJTextField;
35 private JTextField redQuantityJTextField;
36
37 // JLabels for die prices
38 private JLabel priceJLabel;
39 private JLabel whitePriceJLabel;
40 private JLabel redPriceJLabel;
41
42 // JLabel and JTextFields for die subtotals
43 private JLabel totalsJLabel;
44 private JTextField whiteTotalsJTextField;
45 private JTextField redTotalsJTextField;
46
47 // JLabel and JTextField for total before tax
48 private JLabel subtotalJLabel;
49 private JTextField subtotalJTextField;
50
51 // JLabel and JTextField for tax
52 private JLabel taxJLabel;
53 private JTextField taxJTextField;
54
55 // JLabel and JTextField for final total
56 private JLabel totalJLabel;
57 private JTextField totalJTextField;
58
59 // JButton to initiate calculate of user's bill
60 private JButton calculateJButton;
61
62 // no-argument constructor
63 public FuzzyDiceOrderForm()
64 {
65 createUserInterface();
66 }
67
68 // create and position GUI components; register event handlers
69 private void createUserInterface()
70 {
71 // get content pane for attaching GUI components
72 Container contentPane = getContentPane();
73
74 // enable explicit positioning of GUI components
75 contentPane.setLayout( null );
76
77 // set up fuzzyDiceJLabel
78 fuzzyDiceJLabel = new JLabel();
79 fuzzyDiceJLabel.setBounds( 137, 16, 235, 24 );
80 fuzzyDiceJLabel.setText( "Fuzzy Dice" );
81 fuzzyDiceJLabel.setFont(
82 new Font( "Default", Font.PLAIN, 22 ) );
83 contentPane.add( fuzzyDiceJLabel );
84
85 // set up orderNumberJLabel
86 orderNumberJLabel = new JLabel();
87 orderNumberJLabel.setBounds( 15, 65, 100, 16 );
88 orderNumberJLabel.setText( "Order Number:" );
89 contentPane.add( orderNumberJLabel );
90
91 // set up orderNumberJTextField
92 orderNumberJTextField = new JTextField();
93 orderNumberJTextField.setBounds( 111, 65, 48, 21 );
94 orderNumberJTextField.setText( "0" );
95 orderNumberJTextField.setHorizontalAlignment(
96 JTextField.RIGHT );
97 contentPane.add( orderNumberJTextField );
98
99 // set up nameJLabel
100 nameJLabel = new JLabel();
101 nameJLabel.setBounds( 15, 105, 40, 16 );
102 nameJLabel.setText( "Name:" );
103 contentPane.add( nameJLabel );
104
105 // set up nameJTextField
106 nameJTextField = new JTextField();
107 nameJTextField.setBounds( 111, 105, 245, 21 );
108 nameJTextField.setText( "Enter name here" );
109 contentPane.add( nameJTextField );
110
111 // set up addressJLabel
112 addressJLabel = new JLabel();
113 addressJLabel.setBounds( 15, 129, 56, 16 );
114 addressJLabel.setText( "Address:" );
115 contentPane.add( addressJLabel );
116
117 // set up addressJTextField1
118 addressJTextField1 = new JTextField();
119 addressJTextField1.setBounds( 111, 129, 245, 21 );
120 addressJTextField1.setText( "Address Line 1" );
121 contentPane.add( addressJTextField1 );
122
123 // set up addressJTextField2
124 addressJTextField2 = new JTextField();
125 addressJTextField2.setBounds( 111, 153, 245, 21 );
126 addressJTextField2.setText( "City, State, Zip" );
127 contentPane.add( addressJTextField2 );
128
129 // set up typeJLabel
130 typeJLabel = new JLabel();
131 typeJLabel.setBounds( 15, 204, 40, 16 );
132 typeJLabel.setText( "Type:" );
133 contentPane.add( typeJLabel );
134
135 // set up whiteTypeJCheckBox
136 whiteTypeJCheckBox = new JCheckBox();
137 whiteTypeJCheckBox.setBounds( 10, 227, 93, 21 );
138 whiteTypeJCheckBox.setText( "White/Black" );
139 contentPane.add( whiteTypeJCheckBox );
140
141 // set up redTypeJCheckBox
142 redTypeJCheckBox = new JCheckBox();
143 redTypeJCheckBox.setBounds( 10, 252, 88, 21 );
144 redTypeJCheckBox.setText( "Red/Black" );
145 contentPane.add( redTypeJCheckBox );
146
147 // set up quantityJLabel
148 quantityJLabel = new JLabel();
149 quantityJLabel.setBounds( 111, 204, 72, 16 );
150 quantityJLabel.setText( "Quantity:" );
151 contentPane.add( quantityJLabel );
152
153 // set up whiteQuantityJTextField
154 whiteQuantityJTextField = new JTextField();
155 whiteQuantityJTextField.setBounds( 111, 228, 64, 21 );
156 whiteQuantityJTextField.setText( "0" );
157 whiteQuantityJTextField.setHorizontalAlignment(
158 JTextField.RIGHT );
159 contentPane.add( whiteQuantityJTextField );
160
161 // set up redQuantityJTextField
162 redQuantityJTextField = new JTextField();
163 redQuantityJTextField.setBounds( 111, 252, 64, 21 );
164 redQuantityJTextField.setText( "0" );
165 redQuantityJTextField.setHorizontalAlignment(
166 JTextField.RIGHT );
167 contentPane.add( redQuantityJTextField );
168
169 // set up priceJLabel
170 priceJLabel = new JLabel();
171 priceJLabel.setBounds( 196, 204, 72, 16 );
172 priceJLabel.setText( "Price:" );
173 contentPane.add( priceJLabel );
174
175 // set up whitePriceJLabel
176 whitePriceJLabel = new JLabel();
177 whitePriceJLabel.setBounds( 196, 228, 80, 21 );
178 whitePriceJLabel.setText( "$6.25" );
179 contentPane.add( whitePriceJLabel );
180
181 // set up redPriceJLabel
182 redPriceJLabel = new JLabel();
183 redPriceJLabel.setBounds( 196, 252, 80, 21 );
184 redPriceJLabel.setText( "$5.00" );
185 contentPane.add( redPriceJLabel );
186
187 // set up totalsJLabel
188 totalsJLabel = new JLabel();
189 totalsJLabel.setBounds( 267, 204, 72, 16 );
190 totalsJLabel.setText( "Totals:" );
191 contentPane.add( totalsJLabel );
192
193 // set up whiteTotalsJTextField
194 whiteTotalsJTextField = new JTextField();
195 whiteTotalsJTextField.setBounds( 267, 228, 87, 16 );
196 whiteTotalsJTextField.setText( "$0.00" );
197 whiteTotalsJTextField.setEditable( false );
198 whiteTotalsJTextField.setHorizontalAlignment(
199 JTextField.RIGHT );
200 contentPane.add( whiteTotalsJTextField );
201
202 // set up redTotalsJTextField
203 redTotalsJTextField = new JTextField();
204 redTotalsJTextField.setBounds( 267, 252, 87, 16 );
205 redTotalsJTextField.setText( "$0.00" );
206 redTotalsJTextField.setEditable( false );
207 redTotalsJTextField.setHorizontalAlignment(
208 JTextField.RIGHT );
209 contentPane.add( redTotalsJTextField );
210
211 // set up subtotalJLabel
212 subtotalJLabel = new JLabel();
213 subtotalJLabel.setBounds( 196, 293, 72, 16 );
214 subtotalJLabel.setText( "Subtotal:" );
215 contentPane.add( subtotalJLabel );
216
217 // set up subtotalJTextField
218 subtotalJTextField = new JTextField();
219 subtotalJTextField.setBounds( 267, 293, 87, 16 );
220 subtotalJTextField.setText( "$0.00" );
221 subtotalJTextField.setEditable( false );
222 subtotalJTextField.setHorizontalAlignment(
223 JTextField.RIGHT );
224 contentPane.add( subtotalJTextField );
225
226 // set up taxJLabel
227 taxJLabel = new JLabel();
228 taxJLabel.setBounds( 196, 317, 72, 16 );
229 taxJLabel.setText( "Tax:" );
230 contentPane.add( taxJLabel );
231
232 // set up taxJTextField
233 taxJTextField = new JTextField();
234 taxJTextField.setBounds( 267, 317, 87, 16 );
235 taxJTextField.setText( "$0.00" );
236 taxJTextField.setEditable( false );
237 taxJTextField.setHorizontalAlignment(
238 JTextField.RIGHT );
239 contentPane.add( taxJTextField );
240
241 // set up totalJLabel
242 totalJLabel = new JLabel();
243 totalJLabel.setBounds( 196, 341, 72, 16 );
244 totalJLabel.setText( "Total:" );
245 contentPane.add( totalJLabel );
246
247 // set up totalJTextField
248 totalJTextField = new JTextField();
249 totalJTextField.setBounds( 267, 341, 87, 16 );
250 totalJTextField.setText( "$0.00" );
251 totalJTextField.setEditable( false );
252
You might also like to view...
When a comment has been inserted into a presentation, the ________ button contains the initials of the person whose name is registered in the user information in the PowerPoint Options dialog box and a sequence number
A) User name B) Author comment C) Author D) User name comment
Which of the following is not true about the Internet?
A) Internet connections are measured in bytes per second. B) The Internet is the largest network in the world, with millions of computers connected together. C) Users connect to the Internet in a variety of ways and at different speeds. D) To access the Internet, users need an Internet connection.