public class ExprEvaluatorTest
extends java.lang.Object
implements java.awt.event.ActionListener, java.awt.event.FocusListener
The simple minded application alternates between two dialog boxes, one for input and one for output. The output includes the values of t, x, and y, the expression tree, and corresponding prefix and postfix expressions.
An infix expression is the typical way we write algebraic expressions
that uses binary operators between the values they operate on and
uses parenthesis to help determine the order of evaluation and specify
arguments for functions. For example:
x * y + 20
(x-10)/(x+5)
10 * abs(x^2 - y^2)
h = sqrt(x^2 + y^2)
Postfix expressions are written with the value before the operator. This
is sometimes called Reverse Polish notation and is similar to the notation
used in HP calculators. It is particularly convenient for computers. For
example, the above expressions would be
written:
x y * 20 +
x 10 - x 5 + /
10 x 2 ^ y 2 ^ - abs *
h x 2 ^ y 2 ^ + sqrt =
Prefix expressions are written with the operator before the values it
applies to. This notation is also somewhat convenient for computers but
fairly rare. The above examples would be written:
+ * x y 20
/ - x 10 + x 5
* 10 abs - ^ x 2 ^ y 2
= h sqrt + ^ x 2 ^ y 2
| Constructor and Description |
|---|
ExprEvaluatorTest() |
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
Used to process help and exit buttons
|
void |
focusGained(java.awt.event.FocusEvent e)
Used to select all the text whenever the JTextField gets the focus
|
void |
focusLost(java.awt.event.FocusEvent e)
Required to implement FocusListener but does not do anything.
|
static void |
main(java.lang.String[] args)
Main test program.
|
public static void main(java.lang.String[] args)
public void focusGained(java.awt.event.FocusEvent e)
focusGained in interface java.awt.event.FocusListenere - - a Focus eventpublic void focusLost(java.awt.event.FocusEvent e)
focusLost in interface java.awt.event.FocusListenere - - a Focus eventpublic void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed in interface java.awt.event.ActionListenere - - The action event