Write an application that allows users to add appointments to an appointment book that uses the Java Speech API (Fig. 28.18). When the user clicks the Add JButton, the application adds the name, time and date of the appointment to three ArrayLists, respectively. When the user clicks the Get Appointments JButton, the application speaks the time and date of the appointment that the user has with that person.
a) Copying the template to your working directory. Copy the C:Examples Tutorial28ExercisesAppointmentBook directory to your C:SimplyJava direc- tory.
b) Opening the template file. Open the AppointmentBook.java file in your text editor. c) Importing the Java Speech API packages. Import the javax.speech and the
javax.speech.synthesis packages.
d) Declaring instance variables. At line 48, declare three instance variables of type ArrayList to store the date, time and person with which the user has an appoint- ment. Declare an instance variable of type Synthesizer, which will be used to speak text.
e) Creating a Synthesizer object. Inside the AppointmentBook constructor, create a
Synthesizer object, allocate the resource and get the synthesizer ready to speak.
f) Adding code to the addJButtonActionPerformed method. Find the addJButtonAc- tionPerformed method, which immediately follows createUserInterface. Add code to the addJButtonActionPerformed metho
```
1 //
2 //
3 //
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.*;
7 import javax.swing.*;
8 import javax.speech.*;
9 import javax.speech.synthesis.*;
10
11 public class AppointmentBook extends JFrame
12 {
13 // JLabel and JTextField for the name of the person that the
14 // appointment will be with
15 private JLabel appointmentWithJLabel;
16 private JTextField appointmentWithJTextField;
17
18 // JLabel, JSpinner and DateEditor for the date of the
19 // appointment
20 private JLabel appointmentDateJLabel;
21 private JSpinner appointmentDateJSpinner;
22 private JSpinner.DateEditor dateFormat;
23
24 // JLabel and JTextField for the time of the appointment
25 private JLabel appointmentTimeJLabel;
26 private JTextField appointmentTimeJTextField;
27
28 // JButton to add an appointment
29 private JButton addJButton;
30
31 // JButton to get appointment
32 private JButton getAppointmentJButton;
33
34 // arrays to store the month
35 private final String[] threeLettersMonths = {
36 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
37 "Sep", "Oct", "Nov", "Dec" };
38 private final String[] months = { "January", "February", "March",
39 "April", "May", "June", "July", "August", "September",
40 "October", "November", "December" };
41
42 // arrays to store the dates
43 private final String[] threeLettersDays =
44 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
45 private final String[] days = { "Sunday", "Monday", "Tuesday",
46 "Wednesday", "Thursday", "Friday", "Saturday" };
47
48 // ArrayLists to store the date, time and person with which
49 // the user has an appointment.
50 private ArrayList dateArrayList = new ArrayList();
51 private ArrayList timeArrayList = new ArrayList();
52 private ArrayList personArrayList = new ArrayList();
53
54 // Synthesizer to speak text
55 private Synthesizer speechSynthesizer;
56
57 // no-argument constructor
58 public AppointmentBook()
59 {
60 // initialize Synthesizer
61 try
62 {
63 // create SynthesizerModeDesc for FreeTTS synthesizer.
64 SynthesizerModeDesc descriptor = new SynthesizerModeDesc(
65 "Unlimited domain FreeTTS Speech Synthesizer " +
66 "from Sun Labs", null, Locale.US, Boolean.FALSE, null);
67
68 // create a Synthesizer
69 speechSynthesizer = Central.createSynthesizer( descriptor );
70
71 // Synthesizer created successfully
72 if ( speechSynthesizer != null )
73 {
74 // get synthesizer ready to speak
75 speechSynthesizer.allocate();
76 speechSynthesizer.resume();
```
You might also like to view...
A(n) __________ is used to iterate through a collection but cannot remove elements from the collection during the iteration.
Fill in the blank(s) with the appropriate word(s).
The ________ row is the last row in the table and is formatted differently from other rows containing data
A) summary B) footer C) header D) total
You can make an ascending bubble sort move the smallest value to the leftmost location first, and then work toward the right of the array.
Answer the following statement true (T) or false (F)
Which of the following is NOT true about purchasing a domain name?
A. Select one TLD to use for your website. B. Avoid abbreviations and hyphens. C. If possible, use your business or organization name. D. Consider adding words that further specify your website purpose.