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

📄 spstoolthread.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.ext;

import java.awt.AWTEventMulticaster;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//import org.apache.log4j.Logger;

public class SPSToolThread extends Thread {
	private final static int		DEFAULT_PERIOD		= 5000;
//	private static Logger log = Logger.getLogger(SPSToolThread.class);
	
	public final static String	COM_SEND_EVENT		= "SendEvent";
	

	private boolean			endThread = false;
	private boolean			sendEvent = true;
	transient ActionListener	actionListener;
	private String				actionCommand = "";
	private int				period = DEFAULT_PERIOD;

	public SPSToolThread() {
		this(DEFAULT_PERIOD);
	}
	
	public SPSToolThread(int period) {
		this.period = period;
	}
	
	public void run() {
		while (endThread == false) {
///			System.out.println(getClass().toString() + " sendEvent flag = " + sendEvent);
			if (sendEvent) {
///				System.out.println("Thread timer period");
		    	if (actionListener != null) {
//		    		log.debug("New ActionEvent has been actionPerformed!");
		    		setActionCommand(COM_SEND_EVENT);
					actionListener.actionPerformed(
							new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
		    	}
			}
		
			try {
				Thread.sleep(period);
			} catch (InterruptedException e) {
				;
			}
		}
	}
	
	public void setActionCommand(String command) {
		actionCommand = command;
	}
	
	public String getActionCommand() {
		return actionCommand;
	}
	
	public synchronized void addActionListener(ActionListener al) {
		actionListener = AWTEventMulticaster.add(actionListener, al);
	}
	
	public synchronized void removeActionListener(ActionListener al) {
		actionListener = AWTEventMulticaster.remove(actionListener, al);
	}
	
	public synchronized void setEndThreadFlag(boolean endThread) {
		this.endThread = endThread;
	}
	
	public synchronized void setSendEvent(boolean sendEvent) {
		this.sendEvent = sendEvent;
	}
	
}

⌨️ 快捷键说明

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