📄 imagechanger.java
字号:
}
void shrinkImage(Image current, Image next, int dx, int dy) {
int w = next.getWidth(null);
int h = next.getHeight(null);
int nx = (mySize.width - w) / 2;
int ny = (mySize.height - h) / 2;
int cx = (mySize.width - current.getWidth(null)) / 2;
int cy = (mySize.height - current.getHeight(null)) / 2;
int x = nx;
int y = ny;
while (w > 0 && h > 0) {
offScreen.drawImage(current, cx, cy, null);
if (dx != 0) {
offScreen.clipRect(0, 0, x, mySize.height);
} else {
offScreen.clipRect(0, 0, mySize.width, y);
}
offScreen.drawImage(next, nx, ny, null);
offScreen.dispose();
offScreen = offImage.getGraphics();
if (dx != 0) {
offScreen.clipRect(x+w, 0, mySize.width-(x+w), mySize.height);
} else {
offScreen.clipRect(0, y+h, mySize.width, mySize.height-(y+h));
}
offScreen.drawImage(next, nx, ny, null);
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e) {
}
if (dx > 0) {
x += dx;
w -= dx * 2;
} else if (dy > 0) {
y += dy;
h -= dy * 2;
}
offScreen.dispose();
offScreen = offImage.getGraphics();
}
}
void openImage(Image next, int speed) {
double dx, dy;
int nw = next.getWidth(null);
int nh = next.getHeight(null);
int nx = (mySize.width - nw) / 2;
int ny = (mySize.height - nh) / 2;
if (nw < nh) {
dy = (double)speed;
dx = (double)speed * nw / nh;
} else {
dx = (double)speed;
dy = (double)speed * nh / nw;
}
double w = 0;
double h = 0;
double x = mySize.width / 2;
double y = mySize.height / 2;
while (x > nx || y > ny) {
x -= dx;
w += dx * 2;
y -= dy;
h += dy * 2;
offScreen.clipRect((int)x, (int)y, (int)w, (int)h);
offScreen.drawImage(next, nx, ny, null);
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e) {
}
offScreen.dispose();
offScreen = offImage.getGraphics();
}
}
void closeImage(Image current, Image next, int speed) {
double dx, dy;
double w = current.getWidth(null);
double h = current.getHeight(null);
if (w < h) {
dy = (double)speed;
dx = (double)speed * w / h;
} else {
dx = (double)speed;
dy = (double)speed * h / w;
}
int cx = (mySize.width - (int)w) / 2;
int cy = (mySize.height - (int)h) / 2;
double x = cx;
double y = cy;
int nx = (mySize.width - next.getWidth(null)) / 2;
int ny = (mySize.height - next.getHeight(null)) / 2;
while (w > 0 && h > 0) {
x += dx;
w -= dx * 2;
y += dy;
h -= dy * 2;
offScreen.drawImage(next, nx, ny, null);
offScreen.clipRect((int)x, (int)y, (int)w, (int)h);
offScreen.drawImage(current, cx, cy, null);
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e) {
}
offScreen.dispose();
offScreen = offImage.getGraphics();
}
}
void fadeImage(Image current, Image next) {
int x = (mySize.width - current.getWidth(null)) / 2;
int y = (mySize.height - current.getHeight(null)) / 2;
for (int i = 0; i < FADEMAX; i++) {
offScreen.setColor(bgColor);
offScreen.fillRect(0, 0, mySize.width, mySize.height);
offScreen.drawImage(current, x, y, null);
for (int fy = 0; fy < mySize.height; fy += FADEWID) {
for (int fx = 0; fx < mySize.width; fx += FADEWID) {
offScreen.drawImage(fadeImage[i], fx, fy, null);
}
}
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(fadeTime);
} catch (InterruptedException e) {
}
}
x = (mySize.width - next.getWidth(null)) / 2;
y = (mySize.height - next.getHeight(null)) / 2;
for (int i = FADEMAX-1; i >= 0; i--) {
offScreen.setColor(bgColor);
offScreen.fillRect(0, 0, mySize.width, mySize.height);
offScreen.drawImage(next, x, y, null);
for (int fy = 0; fy < mySize.height; fy += FADEWID) {
for (int fx = 0; fx < mySize.width; fx += FADEWID) {
offScreen.drawImage(fadeImage[i], fx, fy, null);
}
}
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(fadeTime);
} catch (InterruptedException e) {
}
}
}
void mosaicImage(Image image) {
int x = 0;
int y = 0;
int n = 0;
int line = mySize.height/mosaicHeight;
if (line*mosaicHeight < mySize.height) line++;
int column = mySize.width/mosaicWidth;
if (column*mosaicWidth < mySize.width) column++;
Point[] p = new Point[line*column];
for (int i = 0; i < p.length; i++) {
p[i] = new Point(i/line, i%line);
}
for (int i = 0; i < p.length; i++) {
int r = (int)(rand.nextFloat()*line*column);
Point tmp = p[i];
p[i] = p[r];
p[r] = tmp;
}
Graphics g = mosaicImage.getGraphics();
g.setColor(bgColor);
g.fillRect(0, 0, mySize.width, mySize.height);
g.drawImage(image, (mySize.width-image.getWidth(null))/2, (mySize.height-image.getHeight(null))/2, null);
g.dispose();
while (n < line*column) {
for (int i = 0; i < mosaicSpeed; i++) {
x = p[n].x;
y = p[n].y;
offScreen.clipRect(x*mosaicWidth, y*mosaicHeight, mosaicWidth, mosaicHeight);
offScreen.drawImage(mosaicImage, 0, 0, null);
offScreen.dispose();
offScreen = offImage.getGraphics();
if (++n >= line*column) break;
}
onScreen.drawImage(offImage, 0, 0, null);
try {
Thread.currentThread().sleep(50);
} catch (InterruptedException e) {
}
}
}
private boolean loadImage(int n) {
drawMessage("Loading image... " + imageFile[n]);
repaint();
try {
tracker.waitForID(n);
} catch (InterruptedException e) {
e.printStackTrace();
return false;
}
if (tracker.isErrorID(n)) {
drawMessage("Error loading image " + imageFile[n]);
repaint();
return false;
}
return true;
}
public void run() {
if (randomOrder) {
current = (int)(rand.nextFloat()*images.length);
}
if (randomEffect) {
change[current] = (int)(rand.nextFloat()*EFFECTNUM+1);
if (change[current] != FADE && change[current] != MOSAIC
&& change[current] != OPEN && change[current] != CLOSE) {
change[current] = (int)(rand.nextFloat()*EFFECTNUM+1);
}
}
if (drawWhileLoading) {
if (loadImage(current) == false) {
return;
}
} else {
for (int i = 0; i < images.length; i++) {
if (loadImage(i) == false) {
return;
}
}
}
drawMessage("");
while (true) {
long stime = System.currentTimeMillis();
int next;
int x = (mySize.width - images[current].getWidth(null)) / 2;
int y = (mySize.height - images[current].getHeight(null)) / 2;
offScreen.setColor(bgColor);
offScreen.fillRect(0, 0, mySize.width, mySize.height);
offScreen.drawImage(images[current], x, y, null);
if (title[current] != null) {
offScreen.setFont(font);
if (fontBackColor != null) {
offScreen.setColor(fontBackColor);
offScreen.fillRect(titleBackArea[current].x, titleBackArea[current].y,
titleBackArea[current].width, titleBackArea[current].height);
}
if (fontLineColor != null) {
offScreen.setColor(fontLineColor);
int len = metrics.stringWidth(title[current]);
offScreen.fillRect(titlePos[current].x, titlePos[current].y, len, 2);
}
if (fontShadowColor != null) {
offScreen.setColor(fontShadowColor);
offScreen.drawString(title[current], titlePos[current].x + 1, titlePos[current].y + 1);
}
offScreen.setColor(fontColor);
offScreen.drawString(title[current], titlePos[current].x, titlePos[current].y);
}
onScreen.drawImage(offImage, 0, 0, null);
if (target != null) {
try {
TextChanger textChanger = (TextChanger)(context.getApplet(target));
if (textChanger != null) {
textChanger.changeText(current);
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (autoLink && !linked && url[current] != null) {
linked = true;
if (frame != null) context.showDocument(url[current], frame);
else context.showDocument(url[current]);
}
if (randomOrder) {
do {
next = (int)(rand.nextFloat()*images.length);
} while (next == current);
} else {
next = current + 1;
if (next >= images.length) {
next = 0;
}
}
if (randomEffect) {
change[next] = (int)(rand.nextFloat()*EFFECTNUM+1);
}
try {
tracker.waitForID(next);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (tracker.isErrorID(next)) {
drawMessage("Error loading image " + imageFile[next]);
repaint();
return;
}
try {
if (time[current] == 0) {
Thread.currentThread().suspend();
} else {
long sleepTime = time[current]-(System.currentTimeMillis()-stime);
if (sleepTime > 0) {
Thread.currentThread().sleep(sleepTime);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
if (title[current] != null) {
offScreen.drawImage(images[current], x, y, null);
onScreen.drawImage(offImage, 0, 0, null);
}
switch (change[current]) {
case NONE :
break;
case SCROLLUP :
scrollImage(images[current], images[next], 0, -scrollSpeed);
break;
case SCROLLDOWN :
scrollImage(images[current], images[next], 0, scrollSpeed);
break;
case SCROLLRIGHT :
scrollImage(images[current], images[next], scrollSpeed, 0);
break;
case SCROLLLEFT :
scrollImage(images[current], images[next], -scrollSpeed, 0);
break;
case TEARVERTICAL :
tearOpenImage(images[next], 0, changeSpeed);
break;
case TEARHORIZONTAL :
tearOpenImage(images[next], changeSpeed, 0);
break;
case OPEN :
openImage(images[next], changeSpeed);
break;
case CLOSE :
closeImage(images[current], images[next], changeSpeed);
break;
case FADE :
fadeImage(images[current], images[next]);
break;
case MOSAIC :
mosaicImage(images[next]);
break;
case TEARUP :
tearImage(images[next], 0, -changeSpeed);
break;
case TEARDOWN :
tearImage(images[next], 0, changeSpeed);
break;
case TEARRIGHT :
tearImage(images[next], changeSpeed, 0);
break;
case TEARLEFT :
tearImage(images[next], -changeSpeed, 0);
break;
case SLIDEUP:
slideImage(images[current], images[next], 0, -scrollSpeed);
break;
case SLIDEDOWN:
slideImage(images[current], images[next], 0, scrollSpeed);
break;
case SLIDERIGHT:
slideImage(images[current], images[next], scrollSpeed, 0);
break;
case SLIDELEFT:
slideImage(images[current], images[next], -scrollSpeed, 0);
break;
case SHRINKVERTICAL:
shrinkImage(images[current], images[next], 0, changeSpeed);
break;
case SHRINKHORIZONTAL:
shrinkImage(images[current], images[next], changeSpeed, 0);
break;
}
current = next;
if (cursorIn) showURL(url[current]);
linked = false;
}
}
private Frame getFrame() {
Component parent = getParent();
while (parent != null && !(parent instanceof Frame)) {
parent = parent.getParent();
}
return (Frame)parent;
}
private void showURL(URL u) {
if (u == null) {
context.showStatus("");
getFrame().setCursor(Frame.DEFAULT_CURSOR);
} else {
context.showStatus(u.toString());
getFrame().setCursor(Frame.HAND_CURSOR);
}
}
public boolean mouseDown(Event evt, int x, int y) {
if (url[current] != null) {
if (frame != null) context.showDocument(url[current], frame);
else context.showDocument(url[current]);
} else {
if (kicker != null) {
kicker.resume();
}
}
return true;
}
public boolean mouseEnter(Event evt, int x, int y) {
cursorIn = true;
showURL(url[current]);
return true;
}
public boolean mouseExit(Event evt, int x, int y) {
cursorIn = false;
showURL(null);
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -