📄 intarraydotanimationview.java
字号:
package graphicAnimation.intContainerAnimationView;
import graphicAnimation.intAnimationView.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
public class IntArrayDotAnimationView extends IntArrayAnimationView {
protected int totalWidth = 500; // 每个元素的宽度
protected int totalHeight = 500; // 各元素之间的间隔
public IntArrayDotAnimationView() { }
public IntArrayDotAnimationView(Point pos, Color color, int totalWidth, int totalHeight) {
super(pos, color);
this.totalWidth = totalWidth;
this.totalHeight = totalHeight;
}
/**
* 以最简单的整数视图创建数组元素的视图
* @param data 待创建视图的数组
*/
public void createElementDotAnimationView(int[] data, int maxValue) {
elements = new IntDotAnimationView[data.length];
int yRatio = 1;
int xRatio = 1;
int radius = 1;
if (2 * maxValue < totalHeight) yRatio = totalHeight/maxValue;
if (2 * data.length < totalWidth) xRatio = totalWidth/data.length;
if (xRatio > 10) radius = xRatio / 4;
for (int i = 0; i < data.length; i++) {
elements[i] = new IntDotAnimationView(data[i], new Point(position.x+i*xRatio, position.y-(data[i]*yRatio)), color, radius);
}
}
/**
* 在屏幕上画出该整数数组
* @param gc 所使用的图形上下文
*/
public void paint(Graphics gc) {
if (!visible) return;
if (elements == null) return;
if (elements.length <= 0) return;
int index = 0;
// 调用元素视图的 paint() 方法画出代表每个元素的矩形框,并在基线下面画出该相应的整数值
for (index = 0; index < elements.length; index++) elements[index].paint(gc);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -