randomlayoutmanager.java

来自「无限传感器网络的模拟结果的图形查看环境」· Java 代码 · 共 42 行

JAVA
42
字号
package animation.layout;import animation.layout.GraphLayoutManager;import java.util.Dictionary;import java.util.Enumeration;import java.awt.Dimension;import animation.Node;/**   RandomLayoutManager provides and implementation of GraphLayoutManager that   merely places nodes at random positions.   This is primarily intended for testing.*/public class RandomLayoutManager extends GraphLayoutManager{    /**       The constructor simply takes the nodes and links as parameters.       @param nodes a dictionary of all nodes, indexed by node address       @param links a vector of links    */    public RandomLayoutManager(Dictionary nodes,java.util.Vector links,			       Dimension screensize) {      super(nodes,links,screensize);    }     /**       doLayout in this class just goes through all the nodes and gives them       random positions.       @param iterations randomlayout will ignore this parameter    */    public void doLayout(int iterations) {      for (Enumeration e=m_nodes.elements();e.hasMoreElements();) {	Node n=(Node)e.nextElement();	n.setX(Math.random()*m_screen.width);	n.setY(Math.random()*m_screen.height);      }    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?