import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image;
import java.awt.Dimension;
/* <applet code="Main.class" width="500" height="500"></applet> */
class ForDimChange {
private int x, y;
this.applet = applet;
x = y = 0;
this.update();
}
void update() {
boolean flag = false;
dim = applet.getSize();
if (x != dim.width) {
x = dim.width;
flag = true;
}
if (y != dim.height) {
y = dim.height;
flag = true;
}
if (flag) {
buff = applet.createImage(x, y);
ct = buff.getGraphics();
}
}
int get_dimx() { return x; }
int get_dimy() { return y; }
Image get_buff
() { return buff
; } }
final static int square_size = 20;
final static int quantum = 5;
boolean chkx = true, chky = true;
int x = 250, y = 140;
ForDimChange fdc;
public void init() {
fdc = new ForDimChange(this);
th.start();
}
public void run() {
try {
while (true) {
fdc.update();
if (chkx) x++; else x--;
if (chky) y++; else y--;
if (x >= fdc.get_dimx() - square_size) chkx = false;
if (x <= 0) chkx = true;
if (y >= fdc.get_dimy() - square_size) chky = false;
if (y <= 0) chky = true;
repaint();
}
}
paint(g);
}
ct = fdc.get_ct();
ct.
setColor(Color.
white); ct.fillRect(0, 0, fdc.get_dimx(), fdc.get_dimy());
ct.fillRect(x, y, square_size, square_size);
g.drawImage(fdc.get_buff(), 0, 0, this);
}
}
/* end */
aW1wb3J0IGphdmEuYXBwbGV0LkFwcGxldDsKaW1wb3J0IGphdmEuYXd0LkdyYXBoaWNzOwppbXBvcnQgamF2YS5hd3QuQ29sb3I7CmltcG9ydCBqYXZhLmF3dC5JbWFnZTsKaW1wb3J0IGphdmEuYXd0LkRpbWVuc2lvbjsKCi8qIDxhcHBsZXQgY29kZT0iTWFpbi5jbGFzcyIgd2lkdGg9IjUwMCIgaGVpZ2h0PSI1MDAiPjwvYXBwbGV0PiAqLwoKY2xhc3MgRm9yRGltQ2hhbmdlIHsKICBwcml2YXRlIERpbWVuc2lvbiBkaW07CiAgcHJpdmF0ZSBJbWFnZSBidWZmOwogIHByaXZhdGUgR3JhcGhpY3MgY3Q7CiAgcHJpdmF0ZSBpbnQ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