欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

actionicon.java

PIY(Program It Yourself)是一个基于Java的应用程序开发环境
JAVA
字号:

package piy;

import javax.swing.*;
import java.awt.Graphics;
import java.awt.dnd.*;
import java.awt.event.*;
import java.util.ArrayList;

/**
* An icon that is displayed and stores both the action and the actionlist of the action
* that it is representing.
* @author David Vivash
* @version 1.0, 17/3/01
*/
public class ActionIcon extends AbstractButton implements MouseListener
{
//	protected static boolean pressed = false;
	private boolean over = false, down = false;
	private ArrayList listeners = new ArrayList(1);

	private PIYAction action	= null;
	private ImageIcon icon	= null;
	private ActionList list	= null;

	public ActionIcon(PIYAction action, ActionList list, ImageIcon icon) {
		super();
		addMouseListener(this);
		this.action	= action;
		this.list	= list;
		this.icon	= icon;
	}

	public void paint(Graphics g) {
		icon.paintIcon(this, g, 0, 0);
	}

	public ActionList getActionList() { return list; }
	public void setActionList(ActionList list) { this.list = list; }

	public PIYAction getPIYAction() { return action; }


	/**
	* Adds an action listener to this icon, which is notified when the icon is clicked on.
	* @param listener the action listener to be notified when this icon is clicked
	*/
	public void addActionListener(ActionListener listener) {
		listeners.add(listener);
	}

	/**
	* Notifies each registered listener that this icon has been clicked
	*/
	private void notifyListeners() {
		for (int i=0; i<listeners.size(); i++)
			((ActionListener)listeners.get(i)).actionPerformed(new ActionEvent(this, 0, ""));
	}

	//--- Mouse listener methods ---
	public void mouseClicked(MouseEvent e) { /*this is caught in mousePressed/mouseReleased pair*/}

	public void mousePressed(MouseEvent e) {
		down = true; over = true;
	}

	public void mouseReleased(MouseEvent e) {
		down = false;
		if (over) notifyListeners();
	}

	public void mouseEntered(MouseEvent e) {
		over = true;
	}
	public void mouseExited(MouseEvent e) {
		over = false;
	}


}

⌨️ 快捷键说明

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