[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Swarm-Support] Java Graphs
From: |
durga bhavani |
Subject: |
Re: [Swarm-Support] Java Graphs |
Date: |
Wed, 23 Nov 2005 20:52:25 -0800 (PST) |
Hello Marcus,
But when I change My progran this way it is getting crashed and it's generating a log file. But I am unable to know why it is doing this.
Could you please take a look at this program at your convience and let me know where I am wrong.
Here are three Programs
1)Test.java
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.gui.Graph;
import swarm.gui.GraphElement;
import swarm.gui.GraphImpl;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.objectbase.SwarmImpl;
import java.io.*;
import java.util.*;
public class Test extends SwarmImpl
{
public void Print1()
{
String colors[]={"red","green","blue"};
Graph graph1;
try
{
System.out.println("Get the graph");
TestObserver testObserver = new TestObserver(getZone());
graph1 = testObserver.getgraph();
testObserver.buildObjects();
for (int i = 1; i < 8; i++) {
System.out.println("Creating Graph Element");
GraphElement ge = graph1.createElement
();
ge.setLabel ("Time Step" + i);
ge.setWidth (2);
ge.setColor (colors[i % 3]);
System.out.println(i);
ge.addX$Y ((5 - i) ^ 2, 1 + i);
ge.addX$Y (i + 9, 10 * Math.sin (Math.PI * i / 10));
}
}
catch(Exception
e)
{
System.out.println("Exception caught because of GroupObserver"+e);
}
}
}
2) TestObserver.java
import swarm.Globals;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.defobj.Zone;
import swarm.gui.Graph;
import swarm.gui.GraphElement;
import swarm.gui.GraphImpl;
import swarm.Selector;
public class TestObserver extends GUISwarmImpl {
public Graph graph;
TestObserver (Zone aZone) {
super (aZone);
}
public Graph getgraph(){
return graph;
}
public Object buildObjects () {
super.buildObjects
();
String colors[] = { "red", "green", "blue" };
graph = new GraphImpl (getZone ());
graph.setWindowTitle ("A Graph");
graph.pack ();
return this;
}
}
3)StartTest.java
import swarm.SwarmEnvironmentImpl;
import swarm.Globals;
import swarm.defobj.Zone;
import swarm.activity.ActionGroupImpl;
import swarm.activity.ActionGroup;
import swarm.activity.Activity;
import swarm.objectbase.SwarmImpl;
import swarm.objectbase.Swarm;
import swarm.Selector;
import java.util.LinkedList;
import java.util.List;
public class StartTest{
public static void main (String args[])
{
Globals.env.initSwarm ("Leader", "0.0", "address@hidden
",args);
TestObserver topLevelSwarm = new TestObserver(Globals.env.globalZone);
Globals.env.setWindowGeometryRecordName(topLevelSwarm,"topLevelSwarm");
System.out.println("Running Simulation");
topLevelSwarm.buildObjects();
topLevelSwarm.buildActions();
topLevelSwarm.activateIn(null);
Test test = new Test();
test.Print1();
topLevelSwarm.go();
System.out.println("Finished
Main");
// topLevelSwarm.drop();
}
}
Thanks a lot
Durga
"Marcus G. Daniels" <address@hidden> wrote:
durga bhavani wrote:
What you want here in Test.java is to reference topLevelSwarm, not make
it again.
One way to do that is to pass it as an argument to Print1.
> TestObserver testObserver = new TestObserver(getZone());
> graph1 = testObserver.getgraph();
Also, the instantiation of `Test' and call to `Print1' should be done
before calling `go' in StartTest.java.
_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support
Yahoo! Music Unlimited - Access over 1 million songs. Try it free.