?? eraser.java
字號:
package test.paint;
import test.paint.*;
import java.awt.*;
import javax.swing.JComponent;
/**
*Eraser類,實現橡皮擦的功能
*作者:曾燕秋
*初始時間:2007 5-17
*最后一次修改時間:2007 6-17
*
*/
public class Eraser extends ResShape {
//聲明一個JComponet對象,獲取當前的背景色
private JComponent board;
/**
* 有參構造函數
*/
public Eraser(JComponent board, Stroke s, int x, int y) {
super(null, s, x, y,0,0);
this.board = board;
}
/**
* 無參構造函數
*/
public Eraser(JComponent board) {
this.board = board;
}
/**
* 用當前背景色畫線作為橡皮擦的功能
*/
public void draw(Graphics2D g) {
g.setColor(board.getBackground());
g.setStroke(stroke);
int[][] points = pointsSet.getPoints();
if (points == null)
return;
int s = points[0].length;
if (s == 1) {
int x = points[0][0];
int y = points[1][0];
g.drawLine(x, y, x, y);
} else {
g.drawPolyline(points[0], points[1], s);
}
}
/**
* Get shapeData,聲明一個StringBuffer變量,把圖片相關信息加入StringBuffer
* 臨時變量中,用于保存圖片信息
* 初始時間:2007 5-17
* 最后一次修改時間 2007 6-17
*/
public String getShapeData() {
int si = 0;
for (int i=0; i<MyPanel.ERASER_STROKES.length; i++) {
if (stroke == MyPanel.ERASER_STROKES[i]) {
si = i;
break;
}
}
StringBuffer buffer = new StringBuffer();
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]);
}
return buffer.toString();
}
/**
* Set shapeData,聲明一個String數組,獲得文件中所保存的相關信息,當打開圖片的
* 時候,把數組中的內容還原,顯示所保存的圖片
* 初始時間:2007 5-17
* 最后一次修改時間 2007 6-17
*/
public void setShapeData(String data) throws Exception {
String splits[] = data.split(":");
stroke = MyPanel.ERASER_STROKES[Integer.parseInt(splits[0])];
for (int i=1; i<splits.length; i+=2) {
pointsSet.addPoint(Integer.parseInt(splits[i]),
Integer.parseInt(splits[i+1]));
}
}
public void setIsFill(boolean x) {
// TODO Auto-generated method stub
}
public void setColor(Color col) {
// TODO Auto-generated method stub
}
public boolean intersects(double x, double y, double w, double h) {
// TODO Auto-generated method stub
return false;
}
public Rectangle getBounds() {
// TODO Auto-generated method stub
return null;
}
public int getX() {
// TODO Auto-generated method stub
return 0;
}
public int getY() {
// TODO Auto-generated method stub
return 0;
}
/**
* 判斷是否是圖形
*/
public boolean isImage() {
// TODO Auto-generated method stub
return false;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -