📄 drawcanvas.java
字号:
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;
// 昤夋偡傞揰偺敿宎
private int radius;
// 棜楌
private MacroCommand history;
// 僐儞僗僩儔僋僞
public DrawCanvas(int width, int height, MacroCommand history) {
setSize(width, height);
setBackground(Color.white);
this.history = history;
init();
}
// 棜楌慡懱傪嵞昤夋
public void paint(Graphics g) {
history.execute();
}
// 弶婜壔
public void init() {
color = Color.red;
radius = 6;
}
// 昤夋
public void draw(int x, int y) {
Graphics g = getGraphics();
g.setColor(color);
g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
}
public void setColor(Color color) {
this.color = color;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -