Java Reference
In-Depth Information
Figure 23.1
The graphical user interface for the
SerialToJavelin
program after
connecting via port
COM2
to the Javelin Stamp card (see Chapter 24) and making
several temperature readings.
The full code for these two classes can be found in the Web Course Chapter 23.
The essential code sections are discussed here. Note that we use the technique dis-
cussed in Chapter 6 in which
SerialToJavelin
implements the
Outputable
interface and provides a text area to display strings from the
print()
and
println()
methods rather than on the console. Figure 23.1 shows the user
interface after the program has received several temperature readings from the
Javelin.
When the program
SerialToJavelin
first begins, it builds a menu with the
names of the serial ports on the platform. It invokes the method
getPorts()
,
shown below, which uses the
CommPortIdentifier
static method
getPor-
tIdentifiers()
to obtain the
CommPortIdentifier
object for each port
on the platform. Those that are serial port types are saved in a
Hashtable
.
. ..The getPorts() method in the class
SerialToJavelin
...
/**
* Use the CommPortIdentifier static method to obtain
*alist of ports on the platform. Pick out the
* serial ports from the list and save in a Hash
* table. Use the port names as keys.
*/
Search WWH ::
Custom Search