Class SearchApplet
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----java.applet.Applet
|
+----SearchApplet
- public class SearchApplet
- extends Applet
- implements Runnable
This applet runs a search algorithm on a tree, taking
user input to determine what to search for within the tree and
producing a visual representation of the search's progress through
the tree.
Uses some of the ideas demonstrated in the sort demo included
with Sun's JDK 1.1.
To use this applet, you would add a tag like the following into your
HTML:
<applet code="SearchApplet.class" width=400 height=350>
<PARAM name=alg value="BreadthFirstSearch">
</applet>
If you are using the Depth-Limited algorithm, which takes a depth
limit, you could also add another PARAM tag to specify that limit:
<PARAM name=depth value="3">
To-do list of improvements
- Allow the user to enter a block of text to be used as the tree
instead of having it hardwired in.
- Along the lines of the first one, have a randomly-generated
"numeric" tree used.
- Allow the user to input the branching factor of the tree, or
perhaps just make this an optional parameter of the applet.
- Author:
- Naomi Novik
-
statusBar
-
-
SearchApplet()
-
-
addString(String)
- Add the specified string to the displayed tree.
-
clearSearch()
- Clear the search information while still preserving the tree.
-
clearTree()
- Clear the tree completely.
-
getAppletInfo()
-
-
getParameterInfo()
-
-
handleEvent(Event)
- Handle events that occur in the applet as a result of user action.
-
init()
- Initialize the applet.
-
insertNode(WNode)
- Insert the specified node into the tree at the next available
spot (depends on branchFactor).
-
pause()
- Pause a while, to make the search progress visually clearer.
-
run()
- Main event loop.
-
stop()
- Stop the applet.
statusBar
public TextField statusBar
SearchApplet
public SearchApplet()
getAppletInfo
public String getAppletInfo()
- Overrides:
- getAppletInfo in class Applet
getParameterInfo
public String[][] getParameterInfo()
- Overrides:
- getParameterInfo in class Applet
init
public void init()
- Initialize the applet.
- Overrides:
- init in class Applet
handleEvent
public boolean handleEvent(Event e)
- Handle events that occur in the applet as a result of user action.
- Overrides:
- handleEvent in class Component
stop
public synchronized void stop()
- Stop the applet. Kill any algorithm that is still
searching.
- Overrides:
- stop in class Applet
run
public void run()
- Main event loop. This will be called by the Thread forked
off in startSearch.
We need to set the search algorithm to be used, using the
name specified in the applet's params.
pause
public void pause()
- Pause a while, to make the search progress visually clearer.
- See Also:
- SearchAlgorithm
clearTree
public void clearTree()
- Clear the tree completely.
addString
public void addString(String s)
- Add the specified string to the displayed tree.
insertNode
public void insertNode(WNode n)
- Insert the specified node into the tree at the next available
spot (depends on branchFactor).
clearSearch
public void clearSearch()
- Clear the search information while still preserving the tree.