Skip to content

Instantly share code, notes, and snippets.

@sfentress
Created December 8, 2008 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfentress/33513 to your computer and use it in GitHub Desktop.
Save sfentress/33513 to your computer and use it in GitHub Desktop.
NetLogo 4.1pre6 Embedding Test
package org.concord.otrunknl4.test;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.nlogo.app.InterfaceComponent;
import org.nlogo.window.InvalidVersionException;
/**
* This test was created to test out the new features in NetLogo 4.1 pre 6. Specifically, it
* was designed to test embedding, controlling and logging of applet-like NetLogo models.
*
* @author sfentress
*
*/
public class NetLogoEmbedTest
{
// Sample nlogo file. Path can be changed to location of model.
// Model loads, but CompilerException is thrown: "Nothing named SCENARIO has been defined..."
final String localModelLocation = System.getProperty("user.home")+"/Daisyworld.nlogo";
// Sample online nlogo file. This does NOT work.
final String urlModelLocation = "http://udl.concord.org/share/models/netlogo/Daisyworld.nlogo";
String modelLocation = localModelLocation;
// String modelLocation = urlModelLocation; // This does NOT work
public NetLogoEmbedTest(){
final JFrame frame = createFrame();
final InterfaceComponent app = new InterfaceComponent(frame);
EventQueue.invokeLater(new Runnable(){
public void run()
{
try {
JScrollPane scroll = new JScrollPane(app);
frame.getContentPane().add(scroll);
frame.pack();
app.open(modelLocation);
frame.setVisible(true);
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidVersionException e) {
e.printStackTrace();
}
}});
}
public static JFrame createFrame(){
JFrame frame = new JFrame("NetLogo Embedding Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(700,400));
return frame;
}
public static void main(String[] args)
{
NetLogoEmbedTest n = new NetLogoEmbedTest();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment