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

📄 network.java

📁 用java写的jt-jpeg。jt表示java time package
💻 JAVA
字号:
/*
 |
 | Network.java
 |
 | Network class
 | James Shin Young
 |
 | Created:  February 12, 1998
 |
 | Copyright (c) 1998 by James Shin Young and the Regents
 | of the University of California.  All rights reserved.
 |
 | Permission to use, copy, modify, and distribute this software
 | and its documentation for NON-COMMERCIAL purposes and without
 | fee is hereby granted provided that this copyright notice
 | appears in all copies.
 |
 */

package jcp;
import java.util.Vector;
import java.util.Enumeration;

/**
 * Networks are components that encapsulate a group of other components
 * @author James Shin Young
 * @see Component
 */

public class Network extends Component
{

///////////////////////////////////////////////////////////////////////////////
//* Private variables

    // A vector of components
    private Vector children;

    // A vector of Portsets that record the external to internal
    // port mappings
    private Vector portReceivers;

///////////////////////////////////////////////////////////////////////////////
//* Constructors

    public Network() {
        children = new Vector();
        portReceivers = new Vector();
    }

    public Network(String name) {
        super(name);
        children = new Vector();
        portReceivers = new Vector();
    }

///////////////////////////////////////////////////////////////////////////////
//* Public methods

    public synchronized boolean add(Component component) {
        if (!children.contains(component)) {
            children.addElement(component);
            component.setContainer(this);
            return true;
        } else {
            return false;
        }
    }

    /**
     *  Removes the specified component from the network
     *  @return true if the component was successfully removed.
     *  false if the component cannot be removed or if the component
     *  was not a member of the network.
     */
    public synchronized boolean remove(Component component) {
        if (children.removeElement(component)) {
            component.setContainer(null);
            return true;
        } else {
            return false;
        }
    }

    /**
     *  Checks to see if the network contains a specified component.
     *  @return true if the argument is a member of the network.
     */
    public boolean contains(Component component) {
        return children.contains(component);
    }

    public Enumeration children() {
        return children.elements();
    }

    /**
     *  Networks have no behavior on their own..
     */
    public void go(Port port) { return; }

    public void enable() {
        super.enable();
        for (int i = 0; i < children.size(); i++) {
            ((Component)children.elementAt(i)).enable();
        }
    }

    public void disable() {
        super.disable();
        for (int i = 0; i < children.size(); i++) {
            ((Component)children.elementAt(i)).disable();
        }
    }

    public void reset() {
        super.reset();
        for (int i = 0; i < children.size(); i++) {
            ((Component)children.elementAt(i)).reset();
        }
    }

    public boolean activate(Port port, Object signal) {
        return true;
    }

    public Port addPort(String name) {
        return super.addPort(false,name);
    }

    protected Port addPort() {
        return super.addPort(false,"");
    }
}

⌨️ 快捷键说明

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