[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: |
Fri, 25 Nov 2005 23:16:22 -0800 (PST) |
Hello Marcus,
Thanks for your Help
This work for me, but not sure how to call the same function from ModelSwarm
When I am trying to call Print1 Method from TestModelSwarm This doen't work
The function doesn't get called from TestModelSwarm
Test.java
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(TestObserver testObserver)
{
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);
}
}
}
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 TestModelSwarm testModelSwarm;
public Graph graph;
TestObserver (Zone aZone) {
super (aZone);
}
public Graph getgraph(){
return graph;
}
public Object buildObjects () {
super.buildObjects
();
String colors[] = { "red", "green", "blue" };
testModelSwarm = new TestModelSwarm();
graph = new GraphImpl (getZone ());
graph.setWindowTitle ("A Graph");
graph.pack ();
Globals.env.createArchivedProbeDisplay (testModelSwarm,"testModelSwarm");
testModelSwarm.buildObjects();
return this;
}
}
TestModelSwarm.java
import swarm.SignatureNotFoundException;
import swarm.Globals;
import swarm.Selector;
import swarm.defobj.Zone;
import swarm.activity.Schedule;
import
swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.activity.ActionGroup;
import swarm.activity.ActionGroupImpl;
import swarm.activity.ActionForEach;
import swarm.objectbase.Swarm;
import swarm.objectbase.SwarmImpl;
import java.io.*;
import java.util.*;
public class TestModelSwarm extends SwarmImpl
{
public ActionGroup modelActions;
public Schedule modelSchedule;
public List leaderList;
ActionForEach[] actionForEach = new ActionForEach[4];
public List getLeaderList () {
System.out.println("returning Leader list");
return leaderList;
}
public Object buildObjects()
{
super.buildObjects();
//System.out.println("I am in
buildobjects");
leaderList = new LinkedList();
Test t;
t = new Test();
leaderList.add(t);
return this;
}
public Object buildActions(){
super.buildActions();
try {
Test protoLeader = (Test) leaderList.get(0);
System.out.println("I am in buildActions");
Selector sel1 = new Selector (protoLeader.getClass (), "Print1", false);
actionForEach[1] = modelActions.createActionForEach$message(leaderList,
sel1);
}
catch (SignatureNotFoundException e) {
e.printStackTrace(System.err);
System.out.println("Exception has occured here signature");
}
catch(Exception e1)
{
e1.printStackTrace();
}
modelSchedule = new ScheduleImpl(getZone(),1);
modelSchedule.at$createAction(0,modelActions);
return this;
}
public Activity activateIn(Swarm swarmContext){
super.activateIn(swarmContext);
modelSchedule.activateIn(this);
return getActivity();
}
}
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);
topLevelSwarm.go();
System.out.println("Finished Main");
// topLevelSwarm.drop();
}
}
Thanks
Durga.
"Marcus G. Daniels"
<address@hidden> wrote:
durga bhavani wrote:
> But when I change My progran this way it is getting crashed and
> it's generating a log file.
This method should take testObserver as an argument. In this way you
can pass in topLevelSwarm and not make two of them.
>
> public void Print1()
Like this:
public void Print1(TestObserver testObserver)
_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support
Yahoo! Music Unlimited - Access over 1 million songs. Try it free.