⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 launchsimulator.java

📁 Sensor net work simulator in Java
💻 JAVA
字号:
import java.awt.*;import java.applet.*;import java.awt.event.*;/** * Animation in Java Article Series * * Source code provided by Heaton Research, Inc. *     http://www.heatonresearch.com/ * Copyright 2005 by Heaton Research, Inc. * * This source code is distributed under a Limited GNU Public * License (LGPL). * * This is a very basic class to demonstrate the use of the * BasicAnimate class. This class shows a white ball that * bounces around the applet. * * @author Jeff Heaton(http://www.jeffheaton.com) * @version 1.0 */public class LaunchSimulator extends BasicAnimate {    private static int iNumOfNodes;    private static SensorNetwork sensorNetwork;    private static int iNumClusters;    /**     * When this class is ran as an application, how wide should it be.     */    public static final int IDEAL_WIDTH = 1000;    /**     * When this class is ran as an application, how tall should it be.     */    public static final int IDEAL_HEIGHT = 700;    /**     * What is the size of the bouncing ball.     */    public final int SIZE = 10;    /**     * What is the current x-coordinate of the ball.     */    private int x = 0;    /**     * What is the current y coordinate of the ball.     */    private int y = 0;    /**     * What is the current x-direction of the ball, 1=right, -1=left     */    private int dx = 1;    /**     * What is the current y-direction of the ball, 1=down, -1=Up     */    private int dy = 1;    /**     * What is the width of the page that we should check, takes into     * account how wide the ball is.     */    private int checkWidth;    /**     * What is the height of the page that we should check, takes into     * account how tall the ball is.     */    private int checkHeight;    /**     * This method sets up the bouncing ball example.     *     */    @Override    public void init() {        super.init();        checkWidth = getWidth() - SIZE;        checkHeight = getHeight() - SIZE;        setPulseLength(10);    }    /**     * This method renders each frame of the bouncing ball.     *     * @param g The off-screen graphics object to paint to.     */    @Override    public void paintOffscreen(Graphics g) {        super.paintOffscreen(g);        sensorNetwork.setGDraw(g);        sensorNetwork.drawNetwork();    }    /**     * The main method is called when the class is to be ran     * as a Java application. This method creates a frame and     * attaches the applet to the frame.     *     * @param args Not used.     */    public static void main(String args[]) {        Applet simulator = new LaunchSimulator();        Frame fMainFrame = new Frame();        fMainFrame.addWindowListener(new WindowAdapter() {            @Override            public void windowClosing(WindowEvent e) {                System.exit(0);            }        });        fMainFrame.add(simulator);        fMainFrame.setTitle("Wireless Sensor Network Simulator");        fMainFrame.setSize(IDEAL_WIDTH + 100, IDEAL_HEIGHT + 100);        fMainFrame.show();        iNumOfNodes = 20;        iNumClusters = 2;        sensorNetwork = new SensorNetwork(iNumOfNodes, IDEAL_WIDTH, IDEAL_HEIGHT, iNumClusters);        sensorNetwork.initializeNetwork();        sensorNetwork.clustering();        simulator.init();    }}

⌨️ 快捷键说明

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