📄 lgcanvas.java
字号:
import java.applet.Applet;
import java.awt.*;
import java.io.PrintStream;
class lgcanvas extends Canvas {
public lgcanvas(int i, int j, lgpaint lgpaint1, Choice choice,
Choice choice1) {
offImage = null;
firstTime = true;
x = 0;
y = 0;
lastX = 0;
lastY = 0;
xCenter = 0;
yCenter = 0;
w = 0;
h = 0;
moveX = 0;
moveY = 0;
resize(i, j);
parent = lgpaint1;
mode = 1;
}
public void clear() {
firstTime = true;
lastX = -1;
lastY = -1;
}
public void draw(int i, int j) {
if (i > d.width)
i = d.width;
if (i < -w)
i = -1;
if (j > d.height)
j = d.height;
if (j < -h)
j = -1;
if (mode == 1)
offGraphics.drawLine(lastX, lastY, i, j);
lastX = i;
lastY = j;
repaint();
}
public void erase() {
Color color = offGraphics.getColor();
offGraphics.setColor(Color.gray);
offGraphics.fillRect(0, 0, d.width, d.height);
repaint();
offGraphics.setColor(color);
}
public void mode(int i) {
mode = i;
}
public boolean mouseDown(Event event, int i, int j) {
set(i, j);
return true;
}
public boolean mouseDrag(Event event, int i, int j) {
draw(i, j);
return true;
}
public boolean mouseMove(Event event, int i, int j) {
move(i, j);
return true;
}
public boolean mouseUp(Event event, int i, int j) {
clear();
return true;
}
public void move(int i, int j) {
moveX = i;
moveY = j;
repaint();
}
public void paint(Graphics g) {
offGraphics.fill3DRect(0, 0, d.width, 5, true);
if (offImage != null)
g.drawImage(offImage, 0, 0, this);
if (mode == 2 && image != null)
g.drawImage(image, moveX - image.getWidth(this) / 2, moveY
- image.getHeight(this) / 2, this);
}
public void set(int i, int j) {
if (mode == 2 && image != null)
offGraphics.drawImage(image, i - image.getWidth(this) / 2, j
- image.getHeight(this) / 2, this);
lastX = i;
lastY = j;
draw(i, j);
}
public void setBackground(int i) {
background = parent.getImage(parent.getDocumentBase(), "back" + i
+ ".jpg");
MediaTracker mediatracker = new MediaTracker(this);
mediatracker.addImage(background, 0);
try {
mediatracker.waitForID(0);
} catch (InterruptedException _ex) {
}
if (background != null) {
offGraphics.drawImage(background, 0, 0, d.width, d.height, this);
repaint();
}
}
public void setMyColor(Color color) {
offGraphics.setColor(color);
}
public void setStamp(int i) {
image = parent.getImage(parent.getDocumentBase(), "stamp" + i + ".gif");
MediaTracker mediatracker = new MediaTracker(this);
mediatracker.addImage(image, 0);
try {
mediatracker.waitForID(0);
} catch (InterruptedException _ex) {
}
}
public void setup() {
d = getSize();
setBackground(Color.white);
System.err.println("Larry's Paint canvas size: " + d.width + " x "
+ d.height);
if (offImage == null) {
offImage = createImage(d.width, d.height);
offGraphics = offImage.getGraphics();
}
offGraphics.setColor(Color.gray);
offGraphics.fillRect(0, 0, d.width, d.height);
offGraphics.setColor(Color.black);
}
public void update(Graphics g) {
paint(g);
}
public final int COLOR = 1;
public final int STAMP = 2;
public final int BACKGROUND = 3;
private Dimension d;
private Image offImage;
private Graphics offGraphics;
private Image image;
private Image background;
private lgpaint parent;
private boolean firstTime;
private int x;
private int y;
private int lastX;
private int lastY;
private int xCenter;
private int yCenter;
private int w;
private int h;
private int moveX;
private int moveY;
private int mode;
private Choice choices;
private Choice selections;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -