📄 imageapplet.java
字号:
import java.applet.Applet;import java.awt.*;import java.awt.image.*;public class imageApplet extends Applet{ Image img = null; MediaTracker tracker = null; int Mx = 0; int My = 0; //鼠标按下的位置 int width = 0; int height = 0; //选定区域的宽和高 public void init() { img = getImage(getCodeBase(), "fun.jpg"); //下载图像 tracker = new MediaTracker(this); tracker.addImage(img, 0); try { tracker.waitForAll(); //等待图像完全下载 } catch(InterruptedException _ex) { } Mx = -1; My = -1; resize(200,200) ; width = 100; height = 100; } public boolean mouseDown(Event event, int i, int j) { Mx = i; My = j; //记录鼠标按下的位置 repaint(); return true; } public void paint(Graphics g) { //由于类component实现了接口ImageObserver,所以方法drawImage //中的ImageObserver型参数为this g.drawImage(img, 0, 30, this); //显示原始图像 g.drawString("This is the original picture", 10,20); if(Mx > 0) { int i = Math.max(0, Mx - width / 2); int j = Math.max(0, My - height / 2); //计算左上角图标 g.drawString("Using copyArea method", 345,20); g.copyArea(i, j, width, height, 336, j); g.drawString("Using clipRect method", 490,20); //将图像的一部分拷贝 g.clipRect(440+i, j, width, height); //设置裁减区域 g.drawImage(img, 440,0, this); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -