© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application.

Slides:



Advertisements
Similar presentations
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Advertisements

 2002 Prentice Hall, Inc. All rights reserved. Chapter 14 – Exception Handling Outline 14.1 Introduction 14.2 When Exception Handling Should Be Used 14.3.
Microsoft Visual Basic: Reloaded Chapter Five More on the Selection Structure.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 15.1 Test-Driving the Craps Game Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 14.1 Test-Driving the Fund Raiser Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Objectives –Display a date and time. –Use a JPasswordField.
1 Class 8. 2 Chapter Objectives Use Swing components to build the GUI for a Swing program Implement an ActionListener to handle events Add interface components.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 6.1 Test-Driving the Wage Calculator Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 16.1 Test-Driving the Flag Quiz Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Introduction to GUI in Java 1. Graphical User Interface Java is equipped with many powerful,easy to use GUI component such as input and output dialog.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Wage Calculator Application: Introducing.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
GUI Components and Design Here we add one more component to our programs, JButtons –JButtons can only be inserted into JPanels (or JApplets) –Clicking.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 18.1 Test-Driving the Microwave Oven Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
GUI Clients 1 Enterprise Applications CE00465-M Clients with Graphical User Interfaces.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 19.1 Test-Driving the Shipping Hub Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 23.1 Test-Driving the Screen Scraping Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 25 – Ticket Information Application Introducing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
1 Class 6. 2 Objectives Objectives Enable your applications to perform actions in response to JButton clicks Get the text the user enters in a textfield.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 22.1 Test-Driving the Typing Skills Developer.
Class Class 20 Objectives Use JCheckbox, JRadioButton, and a JComboBox in a UID.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 12 – Enhancing the Wage Calculator Application.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 8.1 Test-Driving the Car Payment Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 11.1 Test-Driving the Security Panel Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 10.1 Test-Driving the Interest Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
Chapter 11 - A GUI Interacting With a Problem Domain Class1 Chapter 11 A GUI Interacting With a Problem Domain Class 11.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 13.1 Test-Driving the Enhanced Interest Calculator.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 2 – Welcome Application Introduction to Graphical.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Event-Driven Programming F Procedural programming is executed in procedural order. F In event-driven programming, code is executed upon activation of events.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 28.1 Java Speech API 28.2 Downloading and.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 7 ( Book Chapter 14) GUI and Event-Driven Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
Chapter 14 – Exception Handling
A First Look at GUI Applications
“Form Ever Follows Function” Louis Henri Sullivan
Presentation transcript:

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Dental Payment Application 7.2 Constructing the Dental Payment Application 7.3Using JCheckBoxes 7.4Using a Dialog to Display a Message 7.5Logical Operators 7.6Wrap-Up Tutorial 7 – Dental Payment Application Introducing JCheckBox es and Message Dialogs

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Use JCheckBox es to allow users to select options. –Use dialogs to display messages. –Use logical operators to form more complex conditions.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Dental Payment Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Dental Payment Application (Cont.) Figure 7.1 Dental Payment application without input entered. JCheckBox components (unchecked)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5 Figure 7.2 Message dialog appears when no name is entered and/or no JCheckBox es are selected. 7.1 Test-Driving the Dental Payment Application (Cont.) Message dialog Run the Dental Payment application – cd c:\Examples\Tutorial07\ CompletedApplication\DentalPayment – java DentalPayment Click OK JButton to close the dialog

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Test-Driving the Dental Payment Application (Cont.) Figure 7.3 Dental Payment application with input entered and total price of services displayed. JCheckBox components (checked)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Dental Payment Application When the user clicks the Calculate JButton: Input patient name If user has not entered a patient name or has not selected any JCheckBoxes Display error message in dialog Else If Cleaning JCheckBox is selected Add cost of a cleaning to the total If Cavity Filling JCheckBox is selected Add cost of a cavity filling to the total If X-Ray JCheckBox is selected Add cost of an x-ray to the total Display total price of services rendered in dollar format

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Constructing the Dental Payment Application

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es JCheckBox es – small gray square either blank or containing a small checkmark – Properties: – selected property: whether or not a JCheckBox is selected – text property: the text just beside a JCheckBox – bounds property: location of JCheckBox – Methods: – isSelected – returns true if JCheckBox is selected – setText – sets text of JCheckBox – setBounds – sets bounds of JCheckBox state button: a button that has either an on or off state

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.5 Changing the text and bounds properties of cleaningJCheckBox. Use methods setBounds and setText to change JCheckBox properties

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.6 Changing text and bounds properties of cavityFillingJCheckBox.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.7 Changing text and bounds properties of xRayJCheckBox.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.8 Application running after customizing three JCheckBox es.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Use method isSelected to determine if a JCheckBox is selected.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.9 Determining if a JCheckBox has been selected. Calling method isSelected Add this code to add the proper amount to total

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.10 Application running without input. Application calculates a bill of $0.00 when no JCheckBox es are checked

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using JCheckBox es (Cont.) Figure 7.11 Application running with services selected, but no patient name entered.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message Figure 7.12 Message dialog displayed by the application. Close buttonDialog sized to accommodate contents Title barIcon indicates the tone of the message OK JButton allows user to close the dialog

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.) Figure 7.13 Adding an if statement to event handler calculateJButtonActionPerformed. Add this code to verify patient name was entered

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.) Figure 7.14 Message dialog code that displays a message to users. Add an error message Use method showMessageDialog to display error message in separate window

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.) Figure 7.15 Adding an else part to an if statement. Add an else statement Add the right brace to end else statement

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.) Figure 7.17 Application running without a name entered.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.) Figure 7.18 Application running with a name entered, but without any JCheckBox es selected. User must now enter a nameApplication calculates a bill of $0.00 when a name is entered and no JCheckBox es are checked

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Using a Dialog to Display a Message (Cont.)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators Logical operators –&& (conditional AND) –|| (conditional OR) –^ (boolean logical exclusive OR) –! (logical negation)

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Using Conditional AND ( && ) if ( gender.equals( "Female" ) && age >= 65 ) { seniorFemales += 1; }

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Using Conditional OR ( || ) if ( semesterAverage >= 90 || finalExam >= 90 ) { JOptionPane.showMessageDialog( null, "Student grade is A.", "Student Grade", JOptionPane.INFORMATION_MESSAGE ); }

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Using Boolean Logical Exclusive OR ( ^ )

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Using Logical Negation ( ! ) if ( !( grade == value ) ) { displayLabel.setText( "They are not equal!" ); }

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Figure 7.24 Using the && and || logical operators. Inserting a complex expression

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Figure 7.25 Message dialog displayed if no name is entered and no JCheckBox es are selected.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Figure 7.26 Message dialog displayed for incorrect input.

© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Logical Operators (Cont.) Figure 7.27 Running the completed application with correct input.

 2004 Prentice Hall, Inc. All rights reserved. Outline 34 DentalPayment.java (1 of 10) 1 // Tutorial 7: DentalPayment.java 2 // This program calculates the total cost of the bill for a 3 // patient at a dental office. 4 import java.awt.*; 5 import java.awt.event.*; 6 import java.text.*; 7 import javax.swing.*; 8 9 public class DentalPayment extends JFrame 10 { 11 // JLabel that displays header on application window 12 private JLabel dentalPaymentFormJLabel; // JLabel and JTextField for patient name 15 private JLabel patientNameJLabel; 16 private JTextField patientNameJTextField; // JCheckBox and JLabel for cleaning 19 private JCheckBox cleaningJCheckBox; 20 private JLabel cleaningPriceJLabel; // JCheckBox and JLabel for cavity filling 23 private JCheckBox cavityFillingJCheckBox; 24 private JLabel cavityFillingPriceJLabel; 25

 2004 Prentice Hall, Inc. All rights reserved. Outline 35 DentalPayment.java (2 of 10) 26 // JCheckBox and JLabel for X-Ray 27 private JCheckBox xRayJCheckBox; 28 private JLabel xRayPriceJLabel; // JLabel and JTextField for total fee 31 private JLabel totalJLabel; 32 private JTextField totalJTextField; // JButton to initiate calculation of fee 35 private JButton calculateJButton; // no-argument constructor 38 public DentalPayment() 39 { 40 createUserInterface(); 41 } // create and position GUI components; register event handlers 44 private void createUserInterface() 45 { 46 // get content pane for attaching GUI components 47 Container contentPane = getContentPane(); // enable explicit positioning of GUI components 50 contentPane.setLayout( null );

 2004 Prentice Hall, Inc. All rights reserved. Outline 36 DentalPayment.java (3 of 10) // set up dentalPaymentFormJLabel 53 dentalPaymentFormJLabel = new JLabel(); 54 dentalPaymentFormJLabel.setBounds( 19, 19, 235, 28 ); 55 dentalPaymentFormJLabel.setText( "Dental Payment Form" ); 56 dentalPaymentFormJLabel.setFont( 57 new Font( "Default", Font.PLAIN, 22 ) ); 58 dentalPaymentFormJLabel.setHorizontalAlignment( 59 JLabel.CENTER ); 60 contentPane.add( dentalPaymentFormJLabel ); // set up patientNameJLabel 63 patientNameJLabel = new JLabel(); 64 patientNameJLabel.setBounds( 19, 65, 91, 21 ); 65 patientNameJLabel.setText( "Patient name:" ); 66 contentPane.add( patientNameJLabel ); // set up patientNameJTextField 69 patientNameJTextField = new JTextField(); 70 patientNameJTextField.setBounds( 132, 65, 117, 21 ); 71 contentPane.add( patientNameJTextField ); 72

 2004 Prentice Hall, Inc. All rights reserved. Outline 37 DentalPayment.java (4 of 10) 73 // set up cleaningJCheckBox 74 cleaningJCheckBox = new JCheckBox(); 75 cleaningJCheckBox.setBounds( 16, 112, 122, 24 ); 76 cleaningJCheckBox.setText( "Cleaning" ); 77 contentPane.add( cleaningJCheckBox ); // set up cleaningPriceJLabel 80 cleaningPriceJLabel = new JLabel(); 81 cleaningPriceJLabel.setBounds( 211, 112, 38, 24 ); 82 cleaningPriceJLabel.setText( "$35" ); 83 cleaningPriceJLabel.setHorizontalAlignment( JLabel.RIGHT ); 84 contentPane.add( cleaningPriceJLabel ); // set up cavityFillingJCheckBox 87 cavityFillingJCheckBox = new JCheckBox(); 88 cavityFillingJCheckBox.setBounds( 16, 159, 122, 24 ); 89 cavityFillingJCheckBox.setText( "Cavity Filling" ); 90 contentPane.add( cavityFillingJCheckBox ); 91 Customizing cleaningJCheckBox Customizing cavityFilling JCheckBox

 2004 Prentice Hall, Inc. All rights reserved. Outline 38 DentalPayment.java (5 of 10) 92 // set up cavityFillingPriceJLabel 93 cavityFillingPriceJLabel = new JLabel(); 94 cavityFillingPriceJLabel.setBounds( 211, 159, 38, 24 ); 95 cavityFillingPriceJLabel.setText( "$150" ); 96 cavityFillingPriceJLabel.setHorizontalAlignment( 97 JLabel.RIGHT ); 98 contentPane.add( cavityFillingPriceJLabel ); // set up xRayJCheckBox 101 xRayJCheckBox = new JCheckBox(); 102 xRayJCheckBox.setBounds( 16, 206, 122, 24 ); 103 xRayJCheckBox.setText( "X-Ray" ); 104 contentPane.add( xRayJCheckBox ); // set up xRayPriceJLabel 107 xRayPriceJLabel = new JLabel(); 108 xRayPriceJLabel.setBounds( 211, 206, 38, 24 ); 109 xRayPriceJLabel.setText( "$85" ); 110 xRayPriceJLabel.setHorizontalAlignment( JLabel.RIGHT ); 111 contentPane.add( xRayPriceJLabel ); 112 Customizing x RayJCheckBox

 2004 Prentice Hall, Inc. All rights reserved. Outline 39 DentalPayment.java (6 of 10) 113 // set up totalJLabel 114 totalJLabel = new JLabel(); 115 totalJLabel.setBounds( 144, 256, 41, 21 ); 116 totalJLabel.setText( "Total:" ); 117 contentPane.add( totalJLabel ); // set up totalJTextField 120 totalJTextField = new JTextField(); 121 totalJTextField.setBounds( 192, 256, 56, 21 ); 122 totalJTextField.setEditable( false ); 123 totalJTextField.setHorizontalAlignment( JTextField.CENTER ); 124 contentPane.add( totalJTextField ); // set up calculateJButton 127 calculateJButton = new JButton(); 128 calculateJButton.setBounds( 155, 296, 94, 24 ); 129 calculateJButton.setText( "Calculate" ); 130 contentPane.add( calculateJButton ); 131 calculateJButton.addActionListener( new ActionListener() // anonymous inner class 134 {

 2004 Prentice Hall, Inc. All rights reserved. Outline 40 DentalPayment.java (7 of 10) 135 // event handler called when user clicks calculateJButton 136 public void actionPerformed( ActionEvent event ) 137 { 138 calculateJButtonActionPerformed( event ); 139 } } // end anonymous inner class ); // end call to addActionListener // set properties of application’s window 146 setTitle( "Dental Payment" ); // set title bar string 147 setSize( 272, 364 ); // set window size 148 setVisible( true ); // display window } // end method createUserInterface // calculate cost of patient's visit 153 private void calculateJButtonActionPerformed( ActionEvent event ) 154 { 155 // get patient's name 156 String patient = patientNameJTextField.getText(); 157 Obtaining patient name

 2004 Prentice Hall, Inc. All rights reserved. Outline 41 DentalPayment.java (8 of 10) 158 // display error message if no name entered or no box selected 159 if ( ( patient.equals( "" ) ) || 160 ( !cleaningJCheckBox.isSelected() && 161 !cavityFillingJCheckBox.isSelected() && 162 !xRayJCheckBox.isSelected() ) ) 163 { 164 // display error message 165 JOptionPane.showMessageDialog( null, 166 "Please enter a name and check at least one item.", 167 "Missing information", JOptionPane.WARNING_MESSAGE ); 168 } 169 else // otherwise, do calculations 170 { 171 double total = 0.0; // sum of all services provided // if patient had a cleaning 174 if ( cleaningJCheckBox.isSelected() ) 175 { 176 total += 35; // add 35 to total 177 } 178 Using logical operators and JCheckBox method isSelected Displaying a JOptionPane message dialog Examining the selected property of cleaningJCheckBox

 2004 Prentice Hall, Inc. All rights reserved. Outline 42 DentalPayment.java (9 of 10) 179 // if patient had cavity filled 180 if ( cavityFillingJCheckBox.isSelected() ) 181 { 182 total += 150; // add 150 to total 183 } // if patient had x-ray taken 186 if ( xRayJCheckBox.isSelected() ) 187 { 188 total += 85; // add 85 to total 189 } // specify display format 192 DecimalFormat dollars = new DecimalFormat( "$0.00" ); // display total 195 totalJTextField.setText( dollars.format( total ) ); } // end else } // end method calculateJButtonActionPerformed 200 Examining the selected property of cavityFillingJCh eckBox Examining the selected property of xRayJCheckBox Format and display total

 2004 Prentice Hall, Inc. All rights reserved. Outline 43 DentalPayment.java (10 of 10) 201 // main method 202 public static void main( String [] args ) 203 { 204 DentalPayment application = new DentalPayment(); 205 application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } // end method main } // end class DentalPayment