(Enhanced Fuzzy Dice Order Form Application) Enhance the Fuzzy Dice Order Form application from Exercise 7.13 so that when a JCheckBox is deselected, its correspond- ing quantity JTextField is made uneditable and the quantity value is reset to 0 (Fig. 7.33). All the monetary values should also be reset to $0.00. When a JCheckBox is selected, its cor- responding quantity JTextField should then be made editable. Again, all the monetary val- ues should be reset to $0.00. To solve this exercise, you will need to use methods for the JCheckBoxes. Empty methods are provided for you. The steps below will walk you through adding the proper code to these methods.



```

a) Copying the template to your working directory. Copy the C:Examples Tutorial07ExercisesFuzzyDiceOrderFormEnhanced directory to your C:Sim- plyJava directory.

b) Opening the template file. Open the FuzzyDiceOrderForm.java file in your text editor.

c) Customizing the application’s components. Set the editable property of whiteQuan- tityJTextField and redQuantityJTextField to false. You want both JText- Fields to be uneditable at the start of the application. On lines 189 and 198, set the editable property of each JTextField to false after the code that sets each JText- Field text property to "0".

d) Coding the whiteTypeJCheckBoxActionPerformed method. In the whiteType- JCheckBoxActionPerformed method (which is right after the calculateJButton- ActionPerformed method), test whether whiteTypeJCheckBox has been selected. If it has, set whiteQuantityJTextField’s editable property to true. If the JCheckBox has not been selected, set whiteQuantityJTextField’s editable prop


```
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 discount
56 private JLabel discountJLabel;
57 private JTextField discountJTextField;
58
59 // JLabel and JTextField for final total
60 private JLabel totalJLabel;
61 private JTextField totalJTextField;
62
63 // JButton to initiate calculate of user's bill
64 private JButton calculateJButton;
65
66 // no-argument constructor
67 public FuzzyDiceOrderForm()
68 {
69 createUserInterface();
70 }
71
72 // create and position GUI components; register event handlers
73 private void createUserInterface()
74 {
75 // get content pane for attaching GUI components
76 Container contentPane = getContentPane();
77
78 // enable explicit positioning of GUI components
79 contentPane.setLayout( null );
80
81 // set up fuzzyDiceJLabel
82 fuzzyDiceJLabel = new JLabel();
83 fuzzyDiceJLabel.setBounds( 137, 16, 235, 24 );
84 fuzzyDiceJLabel.setText( "Fuzzy Dice" );
85 fuzzyDiceJLabel.setFont(
86 new Font( "Default", Font.PLAIN, 22 ) );
87 contentPane.add( fuzzyDiceJLabel );
88
89 // set up orderNumberJLabel
90 orderNumberJLabel = new JLabel();
91 orderNumberJLabel.setBounds( 15, 65, 100, 16 );
92 orderNumberJLabel.setText( "Order Number:" );
93 contentPane.add( orderNumberJLabel );
94
95 // set up orderNumberJTextField
96 orderNumberJTextField = new JTextField();
97 orderNumberJTextField.setBounds( 111, 65, 48, 21 );
98 orderNumberJTextField.setText( "0" );
99 orderNumberJTextField.setHorizontalAlignment(
100 JTextField.RIGHT );
101 contentPane.add( orderNumberJTextField );
102
103 // set up nameJLabel
104 nameJLabel = new JLabel();
105 nameJLabel.setBounds( 15, 105, 40, 16 );
106 nameJLabel.setText( "Name:" );
107 contentPane.add( nameJLabel );
108
109 // set up nameJTextField
110 nameJTextField = new JTextField();
111 nameJTextField.setBounds( 111, 105, 245, 21 );
112 nameJTextField.setText( "Enter name here" );
113 contentPane.add( nameJTextField );
114
115 // set up addressJLabel
116 addressJLabel = new JLabel();
117 addressJLabel.setBounds( 15, 129, 56, 16 );
118 addressJLabel.setText( "Address:" );
119 contentPane.add( addressJLabel );
120
121 // set up addressJTextField1
122 addressJTextField1 = new JTextField();
123 addressJTextField1.setBounds( 111, 129, 245, 21 );
124 addressJTextField1.setText( "Address Line 1" );
125 contentPane.add( addressJTextField1 );
126
127 // set up addressJTextField2
128 addressJTextField2 = new JTextField();
129 addressJTextField2.setBounds( 111, 153, 245, 21 );
130 addressJTextField2.setText( "City, State, Zip" );
131 contentPane.add( addressJTextField2 );
132
133 // set up typeJLabel
134 typeJLabel = new JLabel();
135 typeJLabel.setBounds( 15, 204, 40, 16 );
136 typeJLabel.setText( "Type:" );
137 contentPane.add( typeJLabel );
138
139 // set up whiteTypeJCheckBox
140 whiteTypeJCheckBox = new JCheckBox();
141 whiteTypeJCheckBox.setBounds( 10, 227, 93, 21 );
142 whiteTypeJCheckBox.setText( "White/Black" );
143 contentPane.add( whiteTypeJCheckBox );
144 whiteTypeJCheckBox.addActionListener(
145
146 new ActionListener() // anonymous inner class
147 {
148 // event handler called when user selects
149 // or deselects whiteTypeJCheckBox
150 public void actionPerformed( ActionEvent event )
151 {
152 whiteTypeJCheckBoxActionPerformed( event );
153 }
154
155 } // end anonymous inner class
156
157 ); // end call to addActionListener
158
159 // set up redTypeJCheckBox
160 redTypeJCheckBox = new JCheckBox();
161 redTypeJCheckBox.setBounds( 10, 252, 88, 21 );
162 redTypeJCheckBox.setText( "Red/Black" );
163 contentPane.add( redTypeJCheckBox );
164 redTypeJCheckBox.addActionListener(
165
166 new ActionListener() // anonymous inner class
167 {
168 // event handler called when user selects
169 // or deselects redTypeJCheckBox
170 public void actionPerformed( ActionEvent event )
171 {
172 redTypeJCheckBoxActionPerformed( event );
173 }
174
175 } // end anonymous inner class
176
177 ); // end call to addActionListener
178
179 // set up quantityJLabel
180 quantityJLabel = new JLabel();
181 quantityJLabel.setBounds( 111, 204, 72, 16 );
182 quantityJLabel.setText( "Quantity:" );
183 contentPane.add( quantityJLabel );
184
185 // set up whiteQuantityJTextField
186 whiteQuantityJTextField = new JTextField();
187 whiteQuantityJTextField.setBounds( 111, 228, 64, 21 );
188 whiteQuantityJTextField.setText( "0" );
189

whiteQuantityJTextField.setEditable( false );
190 whiteQuantityJTextField.setHorizontalAlignment(
191 JTextField.RIGHT );
192 contentPane.add( whiteQuantityJTextField );
193
194 // set up redQuantityJTextField
195 redQuantityJTextField = new JTextField();
196 redQuantityJTextField.setBounds( 111, 252, 64, 21 );
197 redQuantityJTextField.setText( "0" );
198

redQuantityJTextField.setEditable( false );
199 redQuantityJTextField.setHorizontalAlignment(
200 JTextField.RIGHT );
201 contentPane.add( redQuantityJTextField );
202
203 // set up priceJLabel
204 priceJLabel = new JLabel();
205 priceJLabel.setBounds( 196, 204, 72, 16 );
206 priceJLabel.setText( "Price:" );
207 contentPane.add( priceJLabel );
208
209 // set up whitePriceJLabel
210 whitePriceJLabel = new JLabel();
211 whitePriceJLabel.setBounds( 196, 228, 80, 21 );
212 whitePriceJLabel.setText( "$6.25" );
213 contentPane.add( whitePriceJLabel );
214
215 // set up redPriceJLabel
216 redPriceJLabel = new JLabel();
217 redPriceJLabel.setBounds( 196, 252, 80, 21 );
218 redPriceJLabel.setText( "$5.00" );
219 contentPane.add( redPriceJLabel );
220
221 // set up totalsJLabel
222 totalsJLabel = new JLabel();
223 totalsJLabel.setBounds( 267, 204, 72, 16 );
224 totalsJLabel.setText( "Totals:" );
225 contentPane.add( totalsJLabel );
226
227 // set up whiteTotalsJTextField
228 whiteTotalsJTextField = new JTextField();
229 whiteTotalsJTextField.setBounds( 267, 228, 87, 16 );
230 whiteTotalsJTextField.setText( "$0.00" );
231 whiteTotalsJTextField.setEditable( false );
232 whiteTotalsJTextField.setHorizontalAlignment(
233 JTextField.RIGHT );
234 contentPane.add( whiteTotalsJTextField );
235
236 // set up redTotalsJTextField
237 redTotalsJTextField = new JTextField();
238 redTotalsJTextField.setBounds( 267, 252, 87, 16 );
239 redTotalsJTextField.setText( "$0.00" );
240 redTotalsJTextField.setEditable( false );
241 redTotalsJTextField.setHorizontalAlignment(
242 JTextField.RIGHT );
243 contentPane.add( redTotalsJTextField );
244
245 // set up subtotalJLabel
246 subtotalJLabel = new JLabel();
247 subtotalJLabel.setBounds( 196, 293, 72, 16 );
248 subtotalJLabel.setText( "Subtotal:" );
249 contentPane.add( subtotalJLabel );
250
251 // set up subtotalJTextField
252 subtotalJTextField = new JTextField();
253

Computer Science & Information Technology

You might also like to view...

You should leave all rows in Excel ________ until all the formulas are written

Fill in the blank(s) with correct word

Computer Science & Information Technology

Which of the following performs a boxing conversion?

a. int x = 7; b. Integer x = 7; c. Neither of the above. d. Both of the above.

Computer Science & Information Technology

It is always a good practice to test each formula you enter for accuracy

Indicate whether the statement is true or false

Computer Science & Information Technology

A(n) ________ associates matching fields between 2 tables.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology