From: John T. M. <jtm...@em...> - 2007-06-22 03:11:45
|
Brian, I've pasted an abbreviated example below; it seems to do what you described and may give you the solution you need. It's very short so I hope you don't mind that I've omitted comments. The aspect that may be most important is putting the 'clearLines()' and 'addLine(String)' methods in a scheduled action; I think this is what the lines you quote from the documentation intended. Note that you also have to schedule the display update. Your TextDisplay object should be referred to by model-level instance variable. Note also that the example to which you referred makes scheduled actions in a different way (by creating a named 'step' method and passing the name to the schedule object) than I did (by creating a class that extends 'BasicAction' and passing an instance of that class); I hope this doesn't add any confusion. Hope this helps, John //-------------------------------------------------------------------------- ----------------------------------------- package test; import java.awt.Color; import java.awt.Dimension; import uchicago.src.sim.engine.BasicAction; import uchicago.src.sim.engine.Schedule; import uchicago.src.sim.engine.SimInit; import uchicago.src.sim.engine.SimModelImpl; import uchicago.src.sim.gui.DisplaySurface; import uchicago.src.sim.gui.TextDisplay; public class TextDisplayDemo extends SimModelImpl { private Schedule schedule; private TextDisplay textDisplay; private DisplaySurface displaySurf; class UpdateTextDisplay extends BasicAction{ public void execute(){ System.out.println("Running!"); textDisplay.clearLines(); textDisplay.addLine("system time: " + System.currentTimeMillis()); displaySurf.updateDisplay(); } } public void begin() { displaySurf = new DisplaySurface(this, "Text Display Demo"); textDisplay = new TextDisplay(100,100, Color.yellow); displaySurf.addDisplayableProbeable(textDisplay, "text"); displaySurf.setSize(new Dimension(140,140)); displaySurf.setBackground(Color.white); displaySurf.display(); schedule = new Schedule(); schedule.scheduleActionBeginning(0, new UpdateTextDisplay()); } public String[] getInitParam() { return new String[] { }; } public String getName() { return "TextDisplayDemo"; } public Schedule getSchedule() { return schedule; } public void setup() { } public static void main(String[] args){ SimInit init = new SimInit(); TextDisplayDemo model = new TextDisplayDemo(); init.loadModel(model, "", false); } } //-------------------------------------------------------------------------- ----------------------------------------------------- _____ From: rep...@li... [mailto:rep...@li...] On Behalf Of brian glass Sent: Thursday, June 21, 2007 7:22 PM To: rep...@li... Subject: Re: [Repast-interest] TextDisplay I've tried to look for examples and documentation, but I still do not understand how to update the TextDisplay every step. Could somebody please send me an example of this? The example here <http://csustan.csustan.edu/%7Etom/SFI-CSSS/2005/NinaNet2/NinaNet2.java> seems to be using an older version of repast. All I would need is a *Model.java file that uses a TextDisplay, so that I can see how it works. Thanks for your help On 6/21/07, brian glass <bri...@gm...> wrote: I am trying to display text to my display surface. I use the following code to set up a TextDisplay in buildDisplay TextDisplay td = new TextDisplay(20, 20, Color.yellow); displaySurf.addDisplayableProbeable (td, "text"); td.clearLines(); td.addLine("system time: " + System.currentTimeMillis()); However, when the model runs, the time is not updated. It says here <http://repast.sourceforge.net/how-to/display.html#text_display> that "the above would be scheduled to occur every tick, and thus would display a new tick count value each tick of the model." I'm not sure exactly where to put the last 2 lines above. If I don't put them in buildDisplay then how can I access TextDisplay td? Thanks, Brian |