clearal.java

来自「用JAVA写的画图软件」· Java 代码 · 共 36 行

JAVA
36
字号
package graphInterface;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ClearAL implements ActionListener{
	
	private JPanel sourcePanel;

	private JPanel infoPanel;

	public ClearAL(JPanel sp, JPanel ip) {
		sourcePanel = sp;
		infoPanel = ip;
	}

	public void actionPerformed(ActionEvent ae) {
		// 清除对象面板内容
		Graphics sgra = sourcePanel.getGraphics();
		sgra.setColor(sourcePanel.getBackground());
		sgra.fillRect(0, 0, 1000, 1000);
		// 清除信息面板内容
		Graphics igra = infoPanel.getGraphics();
		igra.setColor(infoPanel.getBackground());
		igra.fillRect(0, 0, 1000, 1000);
		// 清除对象面板的鼠标监听器
		MouseListener[] al = sourcePanel.getMouseListeners();
		for (int i = 0; i < al.length; ++i) {
			sourcePanel.removeMouseListener(sourcePanel.getMouseListeners()[i]);
			sourcePanel.removeMouseMotionListener(sourcePanel
					.getMouseMotionListeners()[i]);
		}
	}
}

⌨️ 快捷键说明

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