drawcanvas.java
来自「23种java设计模式」· Java 代码 · 共 34 行
JAVA
34 行
package drawer;
import command.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class DrawCanvas extends Canvas implements Drawable {
// 昤夋怓
private Color color = Color.red;
// 昤夋偡傞揰偺敿宎
private int radius = 6;
// 棜楌
private MacroCommand history;
// 僐儞僗僩儔僋僞
public DrawCanvas(int width, int height, MacroCommand history) {
setSize(width, height);
setBackground(Color.white);
this.history = history;
}
// 棜楌慡懱傪嵞昤夋
public void paint(Graphics g) {
history.execute();
}
// 昤夋
public void draw(int x, int y) {
Graphics g = getGraphics();
g.setColor(color);
g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?