📄 resshape.java
字号:
package test.paint;
import java.awt.*;
import java.awt.event.MouseEvent;
/**
* ResShape抽象类,实现MyShape接口
* PolyLine将继承此类
* 作者:钟雯
* 初始时间:2007 5-15
* 最后一次修改时间:2007 6-13
*/
public abstract class ResShape implements MyShape {
//变量全部声明为protected型,以便子类直接访问
//当前颜色
protected Color color;
//当前宽度
protected Stroke stroke;
//一个PointsSet对象,记录点
protected PointsSet pointsSet;
//记录画刷是是画椭圆模式还是方形模式 flag = 0是椭圆 flag = 1是方形
protected int flag;
//椭圆的半径
protected int radius = 0;
/**
*有参构造函数
*/
protected ResShape(Color c, Stroke s, int x, int y,int z,int f ) {
this();
color = c;
stroke = s;
pointsSet.addPoint(x, y);
radius = z;
flag = f;
}
/**
*无参构造函数
*/
protected ResShape() {
pointsSet = new PointsSet(50);
}
//当鼠标拖动的时候记录点的轨迹
public void processCursorEvent(MouseEvent e, int t) {
if (t != MyShape.CURSOR_DRAGGED)
return;
pointsSet.addPoint(e.getX(), e.getY());
}
//获得图形基本数据,用于保存文件
public String getShapeData() {
int si = 0;
for (int i=0; i<MyPanel.STROKES.length; i++) {
if (stroke == MyPanel.STROKES[i]) {
si = i;
break;
}
}
StringBuffer buffer = new StringBuffer();
buffer.append(color.getRGB());
buffer.append(":");
buffer.append(si);
int[][] ps = pointsSet.getPoints();
for (int i=0; i<ps[0].length; i++) {
buffer.append(":");
buffer.append(ps[0][i]);
buffer.append(":");
buffer.append(ps[1][i]);
}
buffer.append(":");
buffer.append(radius);
buffer.append(":");
buffer.append( flag );
buffer.append(":");
return buffer.toString();
}
//打开文件时,将图片相关信息还原
public void setShapeData(String data) throws Exception {
String splits[] = data.split(":");
color = new Color(Integer.parseInt(splits[0]));
stroke = MyPanel.STROKES[Integer.parseInt(splits[1])];
for (int i=2; i<splits.length-2; i+=2) {
pointsSet.addPoint(Integer.parseInt(splits[i]),
Integer.parseInt(splits[i+1]));
}
radius = Integer.parseInt( splits[splits.length-2] );
flag = Integer.parseInt(splits[splits.length-1] );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -