Class Abacus
Class Abacus
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----Abacus
- public class Abacus
- extends Applet
This is a java-applet simulation of a Chinese abacus.
Each column is stored internally in an integer array called
'column' that is initialized to represent the resting positions of
the beads: 2 bead on top deck row-pos 0 & 1, pos 2 empty; 5 beads
lower deck pos 4-8, pos 3 empty. The initial value is
499d=111110011 where a '1' represents a position that is occupied
by a bead and a '0' represents an empty position. As the beads are
moved, the 1's are shifted (using << and >>) accordingly to
represent their new locations.
The illustration below represents a single column of the abacus.
O represents the bead;
| represents an empty position (the rod)
= represents the frame
============= Row Position (index 'r' )
O 0
O 1 Upper Deck
| 2
=============
| 3
O 4
O 5 Lower Deck
O 6
O 7
O 8
=============
-
Abacus()
-
-
animateBead(int, int)
- Moves the bead specified by r & c in the appropriate direction
-
getAppletInfo()
-
Tourist information.
-
getParameterInfo()
-
Parameters user can customize.(Applet->Info)
-
init()
- Initialize the Abacus by initializing the internal column
array.
-
mouseMove(Event, int, int)
- Track the mouse.
-
mouseUp(Event, int, int)
- Handle a mouse-click.
-
paint(Graphics)
- Draw the abacus :draw the frame, draw the rods & draw the
beads; display the value in the frame.
-
update(Graphics)
-
Abacus
public Abacus()
getAppletInfo
public String getAppletInfo()
- Tourist information. (Applet->Info)
- Overrides:
- getAppletInfo in class Applet
getParameterInfo
public String[][] getParameterInfo()
- Parameters user can customize.(Applet->Info)
- Overrides:
- getParameterInfo in class Applet
init
public void init()
- Initialize the Abacus by initializing the internal column
array. If a "VALUE" resource is specified, set the column array
according to it, instead.
- Overrides:
- init in class Applet
paint
public void paint(Graphics g)
- Draw the abacus :draw the frame, draw the rods & draw the
beads; display the value in the frame.
- Overrides:
- paint in class Component
update
public void update(Graphics g)
- Overrides:
- update in class Component
mouseUp
public boolean mouseUp(Event evt,
int x,
int y)
- Handle a mouse-click.
Convert the x/y position of the click to a row/column equivalent
and move the corresponding bead.
- Parameters:
- evt - the internal AWT event varaible
- x - the x-position of the click, in pixels
- y - the y-position of the click, in pixels
- Overrides:
- mouseUp in class Component
mouseMove
public boolean mouseMove(Event evt,
int x,
int y)
- Track the mouse.
Display help information in the status area as the mouse moves
over various hot-points.
- Parameters:
- evt - the internal AWT event varaible
- x - the x-position of the mouse, in pixels
- y - the y-position of the mouse, in pixels
- Overrides:
- mouseMove in class Component
animateBead
public void animateBead(int r,
int c)
- Moves the bead specified by r & c in the appropriate direction
- Parameters:
- r - is the row number for the bead
- c - is the column number for the bead