sim.app.lightcycles.ControlUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mason Show documentation
Show all versions of mason Show documentation
MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.
The newest version!
/*
Copyright 2006 by Daniel Kuebrich
Licensed under the Academic Free License version 3.0
See the file "LICENSE" for more information
*/
package sim.app.lightcycles;
import java.awt.*;
import java.awt.event.*;
import sim.display.*;
// This class is accurately named ControlUI instead of controlGUI because instead of allowing
// a user to interact with the simulation through graphical widgets, it simply adds keyboard
// control to the display window. This allows the user to control a cycle during the simulation.
public class ControlUI
{
// references to sim with ui, sim state, and selected cycle instance
LightCyclesWithUI lcui;
LightCycles lc;
Cycle c;
// for changing color of user-controlled cycle
sim.portrayal.grid.SparseGridPortrayal2D cyclePortrayal;
public ControlUI( LightCyclesWithUI nlc, sim.portrayal.grid.SparseGridPortrayal2D ncp )
{
lcui = nlc;
lc = (LightCycles)lcui.state;
cyclePortrayal = ncp;
// Allows the display to receive input focus
lcui.display.insideDisplay.setRequestFocusEnabled(true);
try
{
initListeners();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void initListeners()
{
lcui.display.insideDisplay.addKeyListener( new KeyAdapter()
{
public void keyPressed( KeyEvent e )
{
// space = cycle the cycles
if(e.getKeyCode() == KeyEvent.VK_SPACE)
{
for(int x=0;x
© 2015 - 2025 Weber Informatics LLC | Privacy Policy