Class GraphPanel
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----GraphPanel
- class GraphPanel
- extends Panel
- implements Runnable
Run the animation as a separate thread.
-
arcColor1
-
-
arcColor2
-
-
arcColor3
-
-
edgeColor
-
-
edges
-
-
fixedColor
-
-
graph
-
-
nedges
-
-
nnodes
-
-
nodeColor
-
-
nodes
-
-
offgraphics
-
-
offscreen
-
-
offscreensize
-
-
pick
-
-
pickfixed
-
-
random
-
-
relaxer
-
-
selectColor
-
-
stress
-
-
stressColor
-
-
GraphPanel(Graph)
-
-
addEdge(String, String, int)
- Add the edge in between 2 nodes.
-
addNode(String)
- Add the new node in a graph, use random() function to create
x and y coordinates.
-
findNode(String)
- Find if the node is present in a graph.
-
mouseDown(Event, int, int)
- This Mouse event is activated when the mouse button is pressed, takes
x and y coordinates when the mouseDown event occurred.
-
mouseDrag(Event, int, int)
- Handles mouse movements made with the mouse button pressed down
-
mouseUp(Event, int, int)
- Invoked when the mouse button is released.
-
paintNode(Graphics, Node, FontMetrics)
- Draw the graph node.
-
relax()
- To avoid race condition between each thread and to preserve
data integrity of the shared object, the method, relax is synchronized
This method settles the nodes of the polygon e.g.
-
run()
- The thread behavior is implemented here.
-
start()
- start the new thread.
-
stop()
- stop the thread.
-
update(Graphics)
- Update method is invoked by repaint method.
graph
Graph graph
nnodes
int nnodes
nodes
Node nodes[]
nedges
int nedges
edges
Edge edges[]
relaxer
Thread relaxer
stress
boolean stress
random
boolean random
pick
Node pick
pickfixed
boolean pickfixed
offscreen
Image offscreen
offscreensize
Dimension offscreensize
offgraphics
Graphics offgraphics
fixedColor
final Color fixedColor
selectColor
final Color selectColor
edgeColor
final Color edgeColor
nodeColor
final Color nodeColor
stressColor
final Color stressColor
arcColor1
final Color arcColor1
arcColor2
final Color arcColor2
arcColor3
final Color arcColor3
GraphPanel
GraphPanel(Graph graph)
findNode
int findNode(String lbl)
- Find if the node is present in a graph. If yes, return the index,
else add node to a graph.
- Parameters:
- lbl - The label of the node.
- Returns:
- The index of the node.
- See Also:
- addNode
addNode
int addNode(String lbl)
- Add the new node in a graph, use random() function to create
x and y coordinates.
- Parameters:
- lbl - he label of the node.
- Returns:
- The node which is just added.
addEdge
void addEdge(String from,
String to,
int len)
- Add the edge in between 2 nodes.
- Parameters:
- from - From which node.
- to - To which node.
- len - Length of the edge.
- See Also:
- findNode
run
public void run()
- The thread behavior is implemented here. Run method contains
an infinite loop. In each iteration of the loop, the thread
sleeps for 100 milliseconds.
relax
synchronized void relax()
- To avoid race condition between each thread and to preserve
data integrity of the shared object, the method, relax is synchronized
This method settles the nodes of the polygon e.g. if the polygon
has 6 nodes, then it will change the position of the nodes such that,
after the polygon settles down, polygon will have a shape of hexagon.
paintNode
public void paintNode(Graphics g,
Node n,
FontMetrics fm)
- Draw the graph node. Called by the update method.
- Parameters:
- g - The graphics object.
- n - The n'th graph node.
- fm - The FontMetrics.
- See Also:
- update
update
public synchronized void update(Graphics g)
- Update method is invoked by repaint method. The update method
erases any drawing that was previously done on the applet. It
creates the new drawing in the off-screen buffer and then display
the off-screen image onto the window.
- Parameters:
- g - The graphics object.
- Overrides:
- update in class Component
mouseDown
public synchronized boolean mouseDown(Event evt,
int x,
int y)
- This Mouse event is activated when the mouse button is pressed, takes
x and y coordinates when the mouseDown event occurred.
It picks the node which is nearest to the mouse coordinates
where mouse is pressed.
- Parameters:
- evt - The event.
- x - The x coordinate of the mouse button pressed.
- y - The y coordinate of the mouse buttom pressed.
- Returns:
- true.
- Overrides:
- mouseDown in class Component
mouseDrag
public synchronized boolean mouseDrag(Event evt,
int x,
int y)
- Handles mouse movements made with the mouse button pressed down
- Parameters:
- evt - The event.
- x - The x coordinate of the new mouse position.
- y - The y coordinate of the new mouse position.
- Returns:
- true.
- Overrides:
- mouseDrag in class Component
mouseUp
public synchronized boolean mouseUp(Event evt,
int x,
int y)
- Invoked when the mouse button is released.
- Parameters:
- evt - The event.
- x - The x coordinate of the mouse button when released.
- y - The y coordinate of the mouse button when released.
- Returns:
- true.
- Overrides:
- mouseUp in class Component
start
public void start()
- start the new thread.
stop
public void stop()
- stop the thread.