/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
* A simple applet class to demonstrate a sort algorithm.
* You can specify a sorting algorithm using the "alg"
* attribute. When you click on the applet, a thread is
* forked which animates the sorting algorithm.
*
* @author James Gosling
*/
@SuppressWarnings("serial")
/**
* The thread that is sorting (or null).
*/
/**
* The array that is being sorted.
*/
int arr[];
/**
* The high water mark.
*/
/**
* The low water mark.
*/
/**
* The name of the algorithm.
*/
/**
* The sorting algorithm (or null).
*/
/**
* Fill the array with random numbers from 0..n-1.
*/
void scramble() {
initialSize = getSize();
for (int i = a.length; --i >= 0;) {
a[i] = (int) (i * f);
}
for (int i = a.length; --i >= 0;) {
int t = a[i];
a[i] = a[j];
a[j] = t;
}
arr = a;
}
/**
* Pause a while.
* @see SortAlgorithm
*/
void pause() {
}
/**
* Pause a while, and draw the high water mark.
* @see SortAlgorithm
*/
}
/**
* Pause a while, and draw the low&high water marks.
* @see SortAlgorithm
*/
repaint();
}
try {
} catch (InterruptedException e) {
}
}
/**
* Initialize the applet.
*/
public void init() {
at = "BubbleSort";
}
scramble();
addMouseListener(this);
}
public void start() {
scramble();
repaint();
}
/**
* Deallocate resources of applet.
*/
public void destroy() {
removeMouseListener(this);
}
/**
* Paint the array of numbers as a list
* of horizontal lines of varying lengths.
*/
int a[] = arr;
int y = 0;
// Check to see if the applet has been resized since it
// started running. If so, need the deltas to make sure
// the applet is centered in its containing panel.
// The evenX and evenY are because the high and low
// watermarks are calculated from the top, but the rest
// of the lines are calculated from the bottom, which
// can lead to a discrepancy if the window is not an
// even size.
if (deltaY < 0) {
deltaY = 0;
evenY = 0;
}
if (deltaX < 0) {
deltaX = 0;
}
}
// Erase old lines
g.setColor(getBackground());
}
// Draw new lines
}
if (h1 >= 0) {
}
if (h2 >= 0) {
}
}
/**
* Update without erasing the background.
*/
paint(g);
}
/**
* Run the sorting algorithm. This method is
* called by class Thread once the sorting algorithm
* is started.
* @see java.lang.Thread#run
* @see SortItem#mouseUp
*/
public void run() {
try {
}
} catch (Exception e) {
}
}
/**
* Stop the applet. Kill any sorting algorithm that
* is still sorting.
*/
public synchronized void stop() {
try {
} catch (IllegalThreadStateException e) {
// ignore this exception
}
}
}
/**
* For a Thread to actually do the sorting. This routine makes
* sure we do not simultaneously start several sorts if the user
* repeatedly clicks on the sort item. It needs to be
* synchronized with the stop() method because they both
* manipulate the common kicker variable.
*/
private synchronized void startSort() {
}
}
}
}
/**
* The user clicked in the applet. Start the clock!
*/
startSort();
e.consume();
}
}
}
return "Title: SortDemo \nAuthor: James Gosling 1.17f, 10 Apr 1995 \nA simple applet class to demonstrate a sort algorithm. \nYou can specify a sorting algorithm using the 'alg' attribute. \nWhen you click on the applet, a thread is forked which animates \nthe sorting algorithm.";
}
{ "alg", "string",
"The name of the algorithm to run. You can choose from the provided algorithms or suppply your own, as long as the classes are runnable as threads and their names end in 'Algorithm.' BubbleSort is the default. Example: Use 'QSort' to run the QSortAlgorithm class." }
};
return info;
}
}