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

📄 clock.java

📁 用java写的jt-jpeg。jt表示java time package
💻 JAVA
字号:
/*
 |
 | Clock.java
 |
 | Clock class
 | James Shin Young
 |
 | Created:  January 26, 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.
 |
 */

/**
 * @author James Shin Young
 * @see Clocked
 */
package jcp.clocked;
import jcp.*;

public class Clock extends SynchAutonomousComponent
{

    private Port clk;
    private Port control;
    private boolean activated;
    private Object lock;

    public Clock() {

        setName("Clock");
        clk = addPort(false,"clk");

        control = addPort(true,"in");

        activated = false;  // Default state: inactive
        lock = new Object();
        start();
    }

    public void run() {
        while(true) {
            if (activated) {
                notifyCompute();
                notifyUpdate();
            } else {
                synchronized(lock) {
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {}
                }
            }
        }
    }

    public void go(Port p) {
        if (control.signal() == Signal.TRUE) {
            // Start clock..
            synchronized(lock) {
                activated = true;
                lock.notify();
            }

        } else if (control.signal() == Signal.FALSE) {
            // Stop clock..
                activated = false;
        }

    }

    // Notify components to begin their update phases
    private void notifyUpdate() {
        emit(Signal.FALSE,clk);
    }

    // Notify components to begin their compute phases
    private void notifyCompute() {
        emit(Signal.TRUE,clk);
    }
}

⌨️ 快捷键说明

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