|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
Calculator
public class Calculator
A tiny whole-number calculator — stack architecture.
An object of this class is an Applet, featuring the logic (state machine)
and the display of an integer stack calculator. It has four stack
registers (x, y, z and t just like the famous HP pocket
calculators).
Decimal and hexadecimal display and entry are supported.
The number range is (Java) long (64 bit, 2s complement).
This Applet can be used to demonstrate (Java) integer arithmetic as well
as the stack computer architecture.
The keyboard for digits, "Enter" (the stack push) and the
operations is not part of the Applet. (In that sense the Applet is a pure
demo of MatrixDisplay, MatrixTextDisplay and
DisplayPattern.) The (key) entries are supplied by public methods.
The keypad may thus be implemented by buttons in the "forms"
of an embedding HTML page.
See the minimal demo page
calculator.html
and the
source.
Copyright 2001, 2003, 2004, 2009 Albrecht Weinert
MatrixDisplay,
DisplayPattern,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.applet.Applet |
|---|
Applet.AccessibleApplet |
| Nested classes/interfaces inherited from class java.awt.Panel |
|---|
Panel.AccessibleAWTPanel |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
static int |
ANZ_EL
Number of 5*8 elements in display. |
protected boolean |
autoEnter
State: next digit entry will do an Enter (push stack) before. |
protected boolean |
enterTo0
State: next digit entry will clear X before. |
protected boolean |
hex
State: Hex calculator. |
protected MatrixTextDisplay |
md
The display. |
protected static byte[][] |
MINI_E
Display pattern for minified (5*3) E. |
protected static byte[][] |
MINI_H
Display pattern for minified (5*3) H. |
static String |
NVC
Name, version, copyright. |
protected long |
t
Stack register T (Stack is x, y, z, t). |
protected boolean |
thrOn
Do the marquee (running) version display. |
protected long |
x
Main register X (=display register). |
protected long |
y
Stack register Y (Stack is x, y, z, t). |
protected long |
z
Stack register Z (Stack is x, y, z, t). |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
Calculator()
|
|
| Method Summary | |
|---|---|
void |
chgSign()
Change the sign of x: x = -x. |
void |
chgXY()
Exchange x and y. |
void |
clrXclrAll()
Clear X or all registers. |
void |
digIn(int digit)
Entry of a digit (0..9; ..15). |
void |
divide()
Division (integer) x = y / x. |
void |
divide2()
Division and remainder (integer) x,y = (y / x), (x mod y). |
void |
enter()
Push operation respectively Enter. |
void |
init()
Initialising. |
void |
invHex()
Hex-Decimal toggle. |
void |
minus()
Subtraction x = y - x. |
void |
mod()
Modulo (integer remainder) x = y % x. |
void |
multiply()
Multiplication x = x * y. |
void |
paint(Graphics g)
Paint the display. |
void |
plus()
Addition x = y + x. |
void |
reset()
Reset to "power on" state. |
void |
rollDown()
Roll down the stack (t becomes the previous x). |
void |
showX()
Renew the X display. |
void |
update(Graphics g)
Update the display. |
void |
yHx()
Exponent (y power x) x = y ** x. |
| Methods inherited from class java.applet.Applet |
|---|
destroy, getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop |
| Methods inherited from class java.awt.Panel |
|---|
addNotify |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String NVC
protected long x
protected long y
protected long z
protected long t
protected static final byte[][] MINI_H
protected static final byte[][] MINI_E
public static final int ANZ_EL
protected MatrixTextDisplay md
MatrixTextDisplay
object.ANZ_EL) 5 * 8 elements with
2 dots horizontal spacing. The matrix dots itself are sized 4 * 4 pixels
and are densely packed.
protected boolean hex
protected boolean enterTo0
protected boolean autoEnter
protected boolean thrOn
| Constructor Detail |
|---|
public Calculator()
| Method Detail |
|---|
public void init()
init in class Appletpublic void update(Graphics g)
paint() will update all matrix dots without
flickering.
update in class Containerpublic void paint(Graphics g)
update().
paint in class Containerpublic void showX()
public void digIn(int digit)
enter() will be processed before.sign
would be an operation that ends the number entry.)
digit - The digit key entry: 0..9 decimal respectively 0..15 if
hexadecimal. Values out of range will be ignored.public void multiply()
public void divide()
public void divide2()
chgXY() they can be
viewed alternately.
public void mod()
public void yHx()
public void plus()
public void minus()
public void chgSign()
public void invHex()
public void chgXY()
public void rollDown()
public void enter()
auto-cleared before the next
digit entry.
public void reset()
enter()) starts the normal operation.
public void clrXclrAll()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||