Java Reference
In-Depth Information
Introduction
This chapter illustrates how to design and create a Calculator application that
can run as a stand-alone application on any platform, including a desktop or
notebook computer, a PDA, a cellular phone, or a kiosk. Even though most oper-
ating system software comes with a calculator accessory, other systems—such as
a cellular phone, PDA, or kiosk—may not have a calculator immediately available.
In addition, not every location that offers an interactive service wants to open up
its entire system to the public, as is the case with computers and informational
kiosks in libraries, museums, or locations where you pay for usage. Additionally,
many companies want to offer software customers a simple calculator that is eas-
ily accessible from their desktop to help the user quickly determine costs or sav-
ings for their products and services.
In this chapter, as you design and create the calculator application, you will
learn how to create a menu system in Java. Using commands on the menu, users
of the calculator will be able to clear the display, see information about the pro-
gram, and exit the application. Additionally, the calculator will work with the
system clipboard to allow the user to copy and paste data.
You also will learn how to create a GUI using an array of Button objects and
a TextField positioned inside a window to allow a user to perform calculations
and display results. You will learn how to write code to ascertain which button
the user clicked. Finally, you will learn how to set programmed flags to remem-
ber operands and operators needed for compound calculations.
Chapter Six — Calculator Application
A software development firm wants a GUI-based Calculator application written
in Java to offer to its clients. The firm programs interactive kiosks on a variety of
computer system platforms for museums, libraries, school campuses, and other
public places where users have varying levels of access to utility applications,
such as a calculator. The calculator needs to be easy-to-use and portable; further,
it should allow for copying and pasting of results to other programs. A Java pro-
gram is ideal for this purpose because of its ability to load quickly and run
across platforms.
Figure 6-1 displays the calculator with its numeric and operator buttons. The
calculator has a menu with commands such as Clear, Exit, Copy, Paste, and About.
Calculator
application window
menu bar
TextField
Panel with
16 Buttons
FIGURE 6-1
 
Search WWH ::




Custom Search