Application Development


Appendix C. Panther Java Calculator

This appendix contains the development notes for the Panther Java Calculator sample that is located at $SMBASE/samples/javacalc.


Repository Contents

The repository, calc.dic, contains the following items.

Table C-1 Lower Buttons

Repository Name Function Java Class

num_pb

Numeric Keys (also period and +/-)

CalcNum

op_pb

Arithmetic operations

CalcFunc2

mem_pb

Memory functions

CalcMem

misc_pb

Miscellaneous operations (Constants, Clear, backspace)

CalcMisc

Table C-2 Upper Buttons

Repository Name Function Java Class

trig_pb

Trigonometric functions

CalcTrig

mode_pb

Mode change

CalcMode

func1_pb

Single operand functions

CalcFunc1

func2_pb

Two operand functions

CalcFunc2


Calculator Screen

The calculator screen, calc.scr, contains the following widgets and settings.

Table C-3 Screen Properties

Property Setting

IDENTITYTitle

Calculator

IDENTITYJava Tag

CalcScreen

HELPHelp Screen

help.scr

FOCUS->JPL Procedures

global register, memory, operation, op_just_done, degrees, currency

Table C-4 Display Widgets

Widget Name Widget Type Function Java Class

mode_display

Dynamic Label

Displays modes degrees / radians, currency / normal

None

display

Single line text

Calculator display

None

The following table lists the types of push buttons, their names, the push button they inherit from in the repository and the java class.

Table C-5 Button Widgets

Type Name Inherit From Java Class

Digits:

0,1,2,3,4,5,6,7,8,9

nX_pb

(where X is the digit)

Num_pb

CalcNum (Inherited)

. (period)

dot_pb

Num_pb

CalcNum (Inherited)

+/-

sign_pb

Sign_pb

CalcFunc1

C, CE

c_pb, ce_pb

misc_pb

CalcMisc (Inherited)

*, /

mult_pb, div_pb

op_pb

CalcFunc2 (Inherited)

+, -

plus_pb, minus_pb

op_pb

CalcFunc2 (Inherited)

= (Equals)

equls_pb

op_pb

(size changed)

CalcFunc2 (Inherited)

MC, MR

mc_pb, mr_pb

mem_pb

CalcMem (Inherited)

M+

mp_pb

mem_pb

CalcMem (Inherited)

Pi

pi_pb

misc_pb

CalcMisc (Inherited)

_ (Backspace)

bs_pb

misc_pb

CalcMisc (Inherited)

Dg/Rd

angle_pb

mode_pb

CalcMode (Inherited)

#/$

currency_pb

mode_pb

CalcMode (Inherited)

X^Y, Mod

power_pb, mod_pb

func2_pb

CalcFunc2 (Inherited)

Sin, Cos,

Tan, Atan

sin_pb, cos_pb,

tan_pb, atan_pb

trig_pb

CalcTrig (Inherited)

1/x (Inverse)

inv_pb

func1_pb

CalcFunc1 (Inherited)

Sqrt (Square root)

sqr_pb

func1_pb

CalcFunc1 (Inherited)

Log, Exp

log_pb, exp_pb

func1_pb

CalcFunc1 (Inherited)


Java Classes

The Java classes have been broken into handlers which handle either screen entry or "classes" of buttons. This is a mid-way point between having a separate class for each button and having a single class handle all the buttons.

CalcScreen:
Implements ScreenHandler interface

Screen entry function. Initialize global variables and allow backspace, delete and Newline to be caught by ButtonHandler.

Screen exit function. Release backspace, delete, and Newline, restoring normal behavior for those keys.

CalcFunc1:
Implements ButtonHandler interface.

Handles all single operand calculator functions (like Sqrt functions). Also handles the Sign toggle (+/-)

CalcFunc2:
Implements ButtonHandler interface

Handles all dual operand calculator functions. This class actually performs the last stored operation, and stores the next operation in the global variable "operation."

CalcMem:
Implements ButtonHandler interface

Handles all memory functions.

CalcMisc:
Implements ButtonHandler interface

Handles C, CE, backspace and Pi button.

CalcMode:
Implements ButtonHandler interface

Handle mode switching buttons, "Deg/Rad" and "#/$"

CalcTrig:
Implements ButtonHandler interface.

Even though these functions are similar to the CalcFunc1 operations, these make use of the "degrees" setting, so a separate class was created.

CalcNum:
Implements ButtonHandler interface.

Handles all numeric keys, and period.