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

📄 monitor.java

📁 一个简易的轮训小程序 哈哈哈哈哈哈后 嘿嘿嘿嘿黑诶
💻 JAVA
字号:
package org.sadun.util.polling;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;

import javax.swing.JFrame;

import org.sadun.util.CmdLineOptions;

import com.deltax.util.JPanelOutputStream;

/**
 * A very simple example application that shows the directory
 * monitor in action
 *
 * @author C. Sadun
 * @version 1.0
 */
public class Monitor {

    private transient CmdLineOptions co;
    private File [] files;
    private JPanelOutputStream jps;
    private PrintStream ps;
    private DirectoryPoller poller;

    private class MonitorPollManager extends BasePollManager {
        public void fileSetFound(FileSetFoundEvent evt) {
            File [] polledFiles = evt.getFiles();
            for(int i=0;i<polledFiles.length;i++) {
                ps.println("Polled "+polledFiles[i].getAbsolutePath());
            }
        }
    }

    public Monitor() {
        co=new CmdLineOptions();
        co.setOnOption("files", this, "files");
        co.setDescription("files","The directories to monitor");
        co.setMandatory("files", true);
    }

    public void init(String args[]) throws IOException {
        co.parse(args);
        for(int i=0;i<files.length;i++) {
            if (! files[i].isDirectory())
                throw new Error(files[i].getCanonicalPath()+" is not a directory.");
            if (! files[i].exists())
                System.err.println("Warning: "+files[i].getCanonicalPath()+" does not exist.");
        }

        jps= new JPanelOutputStream();
        ps = new PrintStream(jps);
    }

    public void run() {
        JFrame f = new JFrame("Directory monitor");
        f.setSize(300, 300);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(jps.getPanel());
        f.addWindowListener(new WindowAdapter() {
            public void WindowClosing(WindowEvent e) {
                System.err.println("Shutting down poller");
                poller.shutdown();
                //while(poller.isAlive());
                System.err.println("Exiting");
                System.exit(0);
            }

        });

        poller = new DirectoryPoller(files);
        poller.addPollManager(new MonitorPollManager());
        f.setVisible(true);
        poller.start();

    }

    public static void main(String args[]) throws Exception {
    	try {
	        Monitor m = new Monitor();
	        m.init(args);
	        m.run();
    	} catch (CmdLineOptions.OptionException e) {
    		System.err.println(e);
    	}
    }

}

⌨️ 快捷键说明

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