public final class SortApp
extends java.awt.Panel
implements java.lang.Runnable, java.awt.event.MouseListener
SortApp.SortAlgorithm
.
java de.weaut.sortDemo.SortApp BubbleSort
Modifier and Type | Class and Description |
---|---|
static class |
SortApp.SortAlgorithm
An abstract sorting algorithm for demonstrations.
|
Modifier and Type | Field and Description |
---|---|
(package private) java.lang.String |
algName
The algorithm's name.
|
(package private) SortApp.SortAlgorithm |
algorithm
Sorting algorithm (or null).
|
(package private) int[] |
arr
The array to be sorted.
|
(package private) int |
bApp
The frame's width.
|
(package private) java.awt.Color |
bgCol
Background colour.
|
(package private) java.awt.image.BufferedImage |
buffI |
(package private) java.awt.Graphics |
buGr |
(package private) int |
hApp
The frame's height.
|
protected int |
hLcke
Height of the gap between element markers in pixels.
|
protected int |
hStrich
Height of an element marker as horizontal line in pixels.
|
(package private) int |
lArr
The length of the array to be sorted.
|
protected long |
lenPau
Pause in ms for algorithm step display.
|
(package private) int |
obItem
Upper (last) action mark in the course of sorting.
|
(package private) java.util.Random |
rand |
(package private) int |
steps
The step counter.
|
(package private) int |
untItem
Lower (last) action mark in the course of sorting.
|
Constructor and Description |
---|
SortApp(java.lang.String algName)
Constructor as Panel respectively application.
|
Modifier and Type | Method and Description |
---|---|
int[] |
getArr()
The array to be sorted.
|
java.awt.Dimension |
getMinimumSize()
Minimal size.
|
java.awt.Dimension |
getPreferredSize()
Preferred size.
|
static void |
main(java.lang.String[] args)
Start the sorting Demonstration as Java application.
|
void |
mouseClicked(java.awt.event.MouseEvent e) |
void |
mouseEntered(java.awt.event.MouseEvent e) |
void |
mouseExited(java.awt.event.MouseEvent e) |
void |
mousePressed(java.awt.event.MouseEvent e)
Mouse event.
|
void |
mouseReleased(java.awt.event.MouseEvent e)
Mouse event.
|
void |
paint(java.awt.Graphics g)
(Re-) paint the sorting array as pile of horizontal bars.
|
void |
pause(int obItem,
int untItem)
Show the current state / step of the algorithm just working.
|
(package private) boolean |
provideArr()
Providing a new array and buffer, if necessary.
|
void |
run()
The sorting thread.
|
(package private) void |
scramble()
Providing the array to be sorted with shuffled (random) content.
|
protected void |
startSort()
Start the sorting demo.
|
void |
stop()
Sort demo stop.
|
void |
update(java.awt.Graphics g)
Update without clearing.
|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isValidateRoot, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, validate, validateTree
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
int[] arr
shuffled
. It will contain
positive integers smaller than the Frame's width in pixels. algorithm
has to sort it and must mark
substantial steps by one of callback methods pause(int, int)
etc.int obItem
int untItem
java.lang.String algName
SortApp.SortAlgorithm
so named will be looked up in the same package (de.weaut.demos) as
single file or in the application's .jar-File.SortApp.SortAlgorithm algorithm
int hApp
int bApp
int lArr
re-shuffling
. If changed an
new array arr
will be provided accordingly. bApp
, hStrich
and hLcke
just to fill the frame's height but never less than
3.protected int hStrich
protected int hLcke
protected long lenPau
java.util.Random rand
java.awt.image.BufferedImage buffI
java.awt.Graphics buGr
java.awt.Color bgCol
int steps
public SortApp(java.lang.String algName)
public final int[] getArr()
algorithm
has to sort it and must mark
substantial steps by one of callback methods pause(int, int)
etc.boolean provideArr()
array
to be sorted will be provided fitting the height
of the Applet or frame (hApp
), the lines (hStrich
) and
the gaps (hLcke
) if not yet fitting. array
's length will be at least 3 even if the frame
was made to small.array
has been newly madevoid scramble()
provided newly
if necessary.width
- 1) in random order.public void pause(int obItem, int untItem)
array
's
actual state will be displayed and two elements respectively indices
may be marked as to show the current state of work. lenPau
ms pause will be made to view the state. obItem
- upper index or mark (red); or -1 for noneuntItem
- lower index or mark (red); or -1 for nonepublic void paint(java.awt.Graphics g)
paint
in class java.awt.Container
public void update(java.awt.Graphics g)
paint(Graphics)
, which provides flicker free
double buffering.update
in class java.awt.Container
public void run()
SortApp.SortAlgorithm
will be made
and its method sort(int[])
be called.
run
in interface java.lang.Runnable
public void stop()
protected final void startSort()
public void mouseReleased(java.awt.event.MouseEvent e)
start
the sorting demo if not yet running.mouseReleased
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class java.awt.Container
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class java.awt.Container
public static void main(java.lang.String[] args)
SortApp
will as a Panel
be
embedded in a Frame
of original size 520 * 338 and initialised
accordingly. javaw de.weaut.sortDemo.SortApp [AlgName [-option] [x y]]
javaw -jar jarFile [AlgName [-option] [x y]]
java de.weaut.sortDemo.SortApp QuickSort -small 40 15
java -jar sortDemo.jar HeapSort
-small
: height=202, width=300 instead of 520, 338SortApp.SortAlgorithm
. This class will be searched for in the class path
or within this application's .jar-file. args
- [0] : algorithm's short name, default RadixSort;