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

📄 intrectanimationview.java

📁 用JAVA实现排序等简单算法的演示
💻 JAVA
字号:
package graphicAnimation.intAnimationView;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

/**
 * 以矩形条展示整数数据,矩形条的高度与整数数值成正比
 * @author 周晓聪
 * @since 2007/7/1
 *
 */
public class IntRectAnimationView extends IntBoxAnimationView {
	// 矩形条的单位高度,矩形条的高度等于单位高度乘以整数数值
	protected int unitHeight = 1;				
	
	public IntRectAnimationView() { }
	public IntRectAnimationView(int value) { super(value); }
	public IntRectAnimationView(int value, Point pos) { super(value, pos); }
	public IntRectAnimationView(int value, Point pos, Color color) {
		super(value, pos, color);
	}
	public IntRectAnimationView(int value, Point pos, Color color, Color vColor) {
		super(value, pos, color, vColor);
	}
	public IntRectAnimationView(int value, Point pos, Color color, Color vColor, int bWidth) {
		super(value, pos, color, vColor, bWidth);
	}
	public IntRectAnimationView(int value, Point pos, Color color, Color vColor, int bWidth, int uHeight) {
		super(value, pos, color, vColor, bWidth);
		unitHeight = Math.max(uHeight, 1);
	}
	
	/**
	 * 返回矩形条的单位高度
	 */
	public int getUnitHeight() {
		return unitHeight;
	}
	/**
	 * 设置矩形条的单位高度
	 */
	public void setUnitHeight(int unitHeight) {
		this.unitHeight = Math.max(unitHeight, 1);
	}
	/**
	 * 返回矩形条的高度,等于单位高度乘以整数数值
	 */
	public int getHeight() {
		return value * unitHeight;
	}
	
	/**
	 * 以矩形条展示整数数据,矩形条的高度与整数数值成正比
	 * @param gc 展示该整数的图形上下文
	 */
	public void paint(Graphics gc) {
		if (!visible) return;				// 如果不可见,则不绘制
		if (value <= 0) return;			// 如果整数数据小于等于0则不绘制
		int height = value * unitHeight;	
		
		// 以基本颜色填充矩形条,填充的结果使得 position 是矩形条的左下角位置
		gc.setColor(color);
		gc.fillRect(position.x, position.y-height, width, height);
	}
}

⌨️ 快捷键说明

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